COURSES
MBAData Science & AnalyticsDoctorate Software & Tech AI | ML MarketingManagement
Professional Certificate Programme in HR Management and AnalyticsPost Graduate Certificate in Product ManagementExecutive Post Graduate Program in Healthcare ManagementExecutive PG Programme in Human Resource ManagementMBA in International Finance (integrated with ACCA, UK)Global Master Certificate in Integrated Supply Chain ManagementAdvanced General Management ProgramManagement EssentialsLeadership and Management in New Age BusinessProduct Management Online Certificate ProgramStrategic Human Resources Leadership Cornell Certificate ProgramHuman Resources Management Certificate Program for Indian ExecutivesGlobal Professional Certificate in Effective Leadership and ManagementCSM® Certification TrainingCSPO® Certification TrainingLeading SAFe® 5.1 Training (SAFe® Agilist Certification)SAFe® 5.1 POPM CertificationSAFe® 5.1 Scrum Master Certification (SSM)Implementing SAFe® 5.1 with SPC CertificationSAFe® 5 Release Train Engineer (RTE) CertificationPMP® Certification TrainingPRINCE2® Foundation and Practitioner Certification
Law
Job Linked
Bootcamps
Study Abroad
MS in Data AnalyticsMS in Project ManagementMS in Information TechnologyMasters Degree in Data Analytics and VisualizationMasters Degree in Artificial IntelligenceMBS in Entrepreneurship and MarketingMSc in Data AnalyticsMS in Data AnalyticsMS in Computer ScienceMaster of Science in Business AnalyticsMaster of Business Administration MS in Data ScienceMS in Information TechnologyMaster of Business AdministrationMS in Applied Data ScienceMaster of Business Administration | STEMMS in Data AnalyticsM.Sc. Data Science (60 ECTS)Master of Business AdministrationMS in Information Technology and Administrative Management MS in Computer Science Master of Business Administration Master of Business Administration-90 ECTSMSc International Business ManagementMS Data Science Master of Business Administration MSc Business Intelligence and Data ScienceMS Data Analytics MS in Management Information SystemsMSc International Business and ManagementMS Engineering ManagementMS in Machine Learning EngineeringMS in Engineering ManagementMSc Data EngineeringMSc Artificial Intelligence EngineeringMPS in InformaticsMPS in Applied Machine IntelligenceMS in Project ManagementMPS in AnalyticsMS in Project ManagementMS in Organizational LeadershipMPS in Analytics - NEU CanadaMBA with specializationMPS in Informatics - NEU Canada Master in Business AdministrationMS in Digital Marketing and MediaMSc Sustainable Tourism and Event ManagementMSc in Circular Economy and Sustainable InnovationMSc in Impact Finance and Fintech ManagementMS Computer ScienceMBA in Technology, Innovation and EntrepreneurshipMSc Data Science with Work PlacementMSc Global Business Management with Work Placement MBA with Work PlacementMS in Robotics and Autonomous SystemsMS in Civil EngineeringMS in Internet of ThingsMSc International Logistics and Supply Chain ManagementMBA- Business InformaticsMSc International ManagementMBA in Strategic Data Driven ManagementMSc Digital MarketingMBA Business and MarketingMSc in Sustainable Global Supply Chain ManagementMSc Digital Business Analytics MSc in International HospitalityMSc Luxury and Innovation ManagementMaster of Business Administration-International Business ManagementMS in Computer EngineeringMS in Industrial and Systems EngineeringMaster in ManagementMSc MarketingMSc Global Supply Chain ManagementMS in Information Systems and Technology with Business Intelligence and Analytics ConcentrationMSc Corporate FinanceMSc Data Analytics for BusinessMaster of Business AdministrationMaster of Business AdministrationMaster of Business AdministrationMSc in International FinanceMSc in International Management and Global LeadershipMaster of Business AdministrationBachelor of BusinessMaster of Business Administration 60 ECTSMaster of Business Administration 90 ECTSMaster of Business Administration 90 ECTSBachelor of Business AnalyticsBachelor of Information TechnologyMaster of Business AdministrationMBA Business AnalyticsMSc in Marketing Analytics and Data IntelligenceMS Biotechnology Management and EntrepreneurshipMSc in Luxury and Fashion ManagementMaster of Business Administration (90 ECTS)Bachelor of Business Administration (180 ECTS)B.Sc. Computer Science (180 ECTS) MSc in International Corporate Finance MSc in Sustainable Luxury and Creative IndustriesMSc Digital MarketingMSc Global Supply Chain Management (PGMP)MSc Marketing (PGMP)MSc Corporate Finance (PGMP)MSc Data Analytics for Business (PGMP)MS Business AnalyticsMaster of Business AdministrationMS Quantitative FinanceMS Fintech Management
For College Students

How to Start Coding in Javascript - Step by Step Guide

$$/$$

Well, we have discussed a lot about the language. But a basic question that you might be asking yourself is - Where am I supposed to write all the JavaScript code inside the HTML document? And if you have already asked yourself that question, well then, it’s great progress already.

 

All the JavaScript code that you write is inserted between <script> tags like this:

 

<script>
    // JavaScript code
</script>

Now, how exactly do you write the JavaScript code inside the script tags? There are two ways to do so - one way is to use inline scripting, and the other way is to use external scripting.

 

The <script> tags are included either inside <head> tags or the <body> tags.  Remember that even if you break this rule and insert the <script> tags somewhere outside, when you see the output, the browser is smart enough to put it back to its original place (usually inside the <body> tags). 


Let’s discuss inline scripting first. In this approach, as the name suggests, you write everything inline, which means that you include all the code at the current place. Thus, in inline scripting, you write all your JavaScript code inside the <script> tags. We can skip this since we will be using the other way of scripting.

 

The next approach is to use external scripting. In this approach, you write all your JavaScript code in an external file and then reference that file in your HTML document.

 

So, you can change the code written inside your index.html file to the one given below:

 

index.html

<!DOCTYPE html>
<html>
 <head> </head>
 <body>
   <h3>Learning JavaScript</h3>
   <script src="myScript.js">    
   </script>
 </body>
</html>

Notice the changes made in the <script> tags. Here, 'myScript.js' is the file where all the JavaScript code is written that you want to include in your web page.

 

Like a Microsoft Word file is saved with the extension of .doc, which tells the computer that the current file is a Word document, a JavaScript file is saved by the .js extension. Create a new file with the name 'myScript.js' (you can give any other name too) inside your folder where the index.html file is and write the code given below in this file.

 

myScript.js

console.log("Hello World!");

console.log() is a statement that is used to print output on the screen. In the example given above, the console.log() statement will print "Hello World" to the screen.

 

You can also break your code into multiple JavaScript files and give references to all these files in the <script> tags.

 

After you have made all the changes in the code inside both the files, save them. Now, you must be wondering where do I see the output? 

 

Well, you will see the output in the browser, and we prefer Google Chrome as our browser, and we would prefer that you use Google Chrome for this module. However, you can use any browser you feel convenient with.

 

Go to the index.html file in your File Explorer (Windows) or Finder (macOS) and open it by right clicking on the file, and selecting 'Open With' and then choosing 'Google Chrome' as the default application to open all files with .html extension.

 

Your browser, after opening the index.html file, looks like this:

 

 

Now, you have seen where you can write your JavaScript code and how you can write it. You also know that you will see the output on the browser but where exactly will you see it? It is now time to discuss where you can view the output of your JavaScript code inside the browser. 


On the web page which is opened (index.html in our case), right-click on the web page and click on Inspect.

 

 

This will open up a small sub-window. This sub-window is called Developer Tools or DevTools in short. This helps web developers to access deep internals of their web applications on the browser.

 

You can read more about Chrome Developer Tools from this link and about Firefox Developer Tools from this link. We will be using Chrome Developer Tools in this module because we are using Google Chrome browser.

 

You can see this window on the right side or at the bottom, as per your settings but you can always position it as per your convenience. Click on the three dots on the toolbar at the top of the window and then click on an icon in ‘Dock Side’ option to choose the location where you want to position this window. With this option, you can choose to position the DevTools at either right, left, bottom or in a new window by clicking this button.

 

 

This should open something similar to the screen given below. There would be many tabs available in the DevTools window. Choose the Console tab for viewing the output.

 

 

Voila! You get to see 'Hello World'.

$$/$$

Let’s start coding in JavaScript from the next segment onward.