A JavaScript file can be run in the terminal only if you have Node.Js in your system. If you don't have Node.js installed in your system then you can get it installed from this link.

Procedure

If you are done with the installation process we can move ahead to execute it in the terminal.

Step 1: Save your javascript with .js extension.

Step 2: Open the command prompt

Step 3:  Locate your path where the .js file is saved.

Step 4: To compile the .js file we have to write

Node <Filename>.js

Step 5: Press the Enter key.

Example

The above script file will be executed in the command prompt.

Then contents of the javascript file.

const add = (a, b) => {
return a + b
}

console.log(add(4, 6))

Output:

10

write your code here: Coding Playground