Different ways to run JavaScript

DevJunctionPoint
0

 


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
    

Tags

Post a Comment

0Comments

Do leave your comments

Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Ok, Go it!
To Top