You can run your JavaScript file from your terminal only if you have installed Node.Js in your system. Install Node.js from Steps to install Node.js.
If you have already installed it, then simply open the terminal and type “node <FileName>.js”.
Example 1: Create a JavaScript file. Name this file as New.js.
javascript
const add = (a, b) => {
return a + b
}
console.log(add(4, 6))
|
Output:
10
Steps :
- Open Terminal or Command Prompt.
- Set Path to where New.js is located (using cd).
- Type “node New.js” and press ENTER.
Example 2: Create a JavaScript File Name this file as New2.js.
javascript
const sub = (a, b) => {
return a - b
}
console.log(sub(6, 2))
|
Output:
4
JavaScript is best known for web page development but is also used in various non-browser environments. You can learn about JavaScript from the ground up by following JavaScript Tutorial and JavaScript Examples.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!