Different ways to run JavaScript

 


Different ways to run JavaScript

  • Using the browser console tab
  • Using Node.js
  • By creating Web Pages

Using the browser console tab

Almost every popular web browsers have built-in JavaScript engines. Where you can run JavaScript on a browser. To run JavaScript on browsers follow these steps

  • Open your web browser (I'm using Google Chrome).
  • Right-click on the display and select Inspect. (F12 shortcut).

  • Now on the developer tools select the Console tab and then start writing your javascript code.

Using Node.js

Node is a back-end run-time environment for executing JavaScript code. To run JS using Node.js, follow these steps:
  • Install the latest version of Node.js.
  • Install an IDE/Text Editor like Visual Studio Code. In VS code, create a file > write JS code > save it with the .js extension
  • Open up the terminal/command prompt > navigate to the file location > type node hello.js > hit enter.
By Creating Web Pages

  • Open VS Code > Go to File > New File > Save it with .html extension. For example, main.html.
  • Copy this doctype (minimum valid HTML code) and save it in the file.

  • Similarly create a JS file, write the following JS code and save it with .js extension like main.js.
console.log('hello world');


  • From inside the HTML file, we need to link the main.js file to use it. You can achieve that by adding the following code in main.html.

<script scr="main.js"></script>

  • Open the main.html file using a browser.
  • To check if our JS code ran or not, Right click on the web page > Inspect > Choose console tab
    

Related Posts:

  • OperatorWhat is an Operator?In JavaScript, an operator is a special symbol used to perform operations on operands (values and variables).example:   … Read More
  • Data Types In JavaScriptWhat are Data Types?In JavaScript, Data types are defined as what type of value can be stored inside the variables.There are two types of data types i… Read More
  • Variables in JavaScript What are variables?variables act as containers that can store the data.JavaScript Variable Naming RulesVariable names are case-sensitive "a" and… Read More
  • Conditions ConditionalsConditional statements are used for making decisions.JavaScript script executed sequentially from top to bottom.If the processing lo… Read More
  • JavaScript Comments JavaScript CommentsJavaScript comments are hints that a programmer can add to make their code easier to read and understand. They are compl… Read More

0 Comments:

Post a Comment

Do leave your comments