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:

  • Checking Data Type and Type Conversion JavaScript Type Conversions and Checking Data typeTo check the data type of a certain variable we use the typeof method.Type conversion is the p… Read More
  • Different ways to run JavaScript Different ways to run JavaScriptUsing the browser console tabUsing Node.jsBy creating Web PagesUsing the browser console tabAlmost every popular… Read More
  • Comparison and Logical Operator JavaScript Comparison and Logical OperatorsComparison operators compare two values and give back a boolean value: either true or false. Com… Read More
  • Loops LoopsLoops are used in programming to automate repetitive tasks.Most of the activities we do in life are full of repetitions. Imagine if I ask y… Read More
  • Console Objects and Method What is a JavaScript Console Object?JavaScript console object provides access to the browser's debugging console.It is the property of the windo… Read More

0 Comments:

Post a Comment

Do leave your comments