How do you run JavaScript script through the Terminal?

You can Run your JavaScript File from your Terminal provided that you have introduced NodeJs runtime. On the off chance that you have Installed it then, at that point, Simply open the terminal and type “hub FileName.js”. On the off chance that you don’t have NodeJs runtime climate then, at that point, go to NodeJs Runtime Environment Download and Download it.

To run JavaScript code in Your Terminal first you want to introduce NodeJs. The following stage is to open terminal and run hub order (on the off chance that you don’t have NodeJs then, at that point, go to NodeJs Runtime Environment Download and Download it.):

You can run JavaScript console in terminal or any order line interface utilizing Node.js, an open-source, stage freethinker runtime that executes JavaScript outside an internet browser.

Figure out how to run JavaScript documents in the terminal or from the order brief by utilizing the NodeJs runtime climate. JavaScript is a prearranging language for making pages intelligent that implies it’s deciphered in the program as it were. Hence you can run js record in the terminal if by some stroke of good luck you have NodeJs introduced on your PC.

How do you run JavaScript script through the Terminal?

So we first need to introduce it, so open this connect to download NodeJs runtime climate. Then, at that point, open the downloaded .exe record and introduce it on your framework universally. In the event that you have it introduced on your framework as of now, then, at that point, you are allowed to avoid this progression.

Example 1: Create a JavaScript File Name this file as New.js.

// Simple Addition Function in Javascript
function add(a, b) {
return a+b
}
console.log(add(4, 6))

Output:

10

Steps :

  1. Open Terminal or Command Prompt.
  2. Set Path to where File is Located (using cd).
  3. Type “node New.js” and Click Enter

Examples 2: Create a JavaScript File Name this file as New2.js.

// Simple Substraction Function in Javascript
function sub(a, b) {
return a-b
}
console.log(sub(6, 2))

Output:

4

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.

Also ReadDifference between Worms and Trojan Horse

Leave a Reply

Your email address will not be published. Required fields are marked *