JavaScript is a versatile, high-level programming language that is widely supported across all major operating systems.
You can run JavaScript on your computer using the following two methods:
- Run JavaScript online
- Run JavaScript on your computer
In this tutorial, you will learn both methods.
Run JavaScript Online
You can try our free online JavaScript compiler to run JavaScript code directly in your browser without any need for installation.
![Online JavaScript Compiler Online JavaScript Compiler](/sites/tutorial2program/files/programiz-compiler-js-getting-started.png)
Run JavaScript on Your Computer
If you prefer to run JavaScript locally on your computer, this guide will walk you through the steps needed for Windows, macOS, or Linux (Ubuntu).
To install JavaScript on your Windows, just follow these steps:
- Install VS Code
- Download Node msi file
- Install Node
- Verify your installation
Here is a detailed explanation of each of the steps:
Step 1: Install VS Code
Go to the VS Code Official website and download the Windows installer. Once the download is complete, run the installer and follow the installation process.
Click Finish to complete the installation process
Step 2: Download the Node File
Go to the official Node website and download the Node LTS version.
![JavaScript Download Page JavaScript Download Page](/sites/tutorial2program/files/javascript-downloading-page1.png)
Step 3: Run the Installer
Now, go to your download folder and run the msi file you just downloaded. Depending on your security settings, you might be prompted to allow access. Just click on Next.
Simply allow it and proceed.
Then you will come across the install part.
![Install JavaScript on Windows Install JavaScript on Windows](/sites/tutorial2program/files/javascript-install-windows1.png)
Simply click on install, Node will be successfully installed in your device.
![JavaScript Installation JavaScript Installation](/sites/tutorial2program/files/javascript-install-javascript.png)
Step 4: Verify your installation
After the installation is complete, you can verify whether JavaScript is installed by using the following command in the command prompt.
node --version
![JavaScript Installation Verification for Windows JavaScript Installation Verification for Windows](/sites/tutorial2program/files/javascript-installation-verify1.png)
Note: The version number might differ from the one above, depending on your installed version.
Now, you are all set to run JavaScript programs on your device.
To install JavaScript on your Mac OS, just follow these steps:
- Install VS Code
- Download Node.js Package
- Install Node.js
- Verify your installation
Here is a detailed explanation of each of the steps:
Step 1: Install VS Code
Go to the VS Code Official website and download the Mac installer. Once the download is complete, open the .dmg file and drag Visual Studio Code to your Applications folder.
Click Finish to complete the installation process
Step 2: Download the Node.js File
Go to the official Node website and download the Node LTS version.
![JavaScript Download Page JavaScript Download Page](/sites/tutorial2program/files/javascript-downloading-page1.png)
Step 3: Run the Installer
Open the downloaded .pkg file and follow the on-screen instructions to install Node.js. You'll be guided through the installation process; just follow the prompts and agree to the license agreement.
Simply allow it and proceed.
Then you will come across the install part.
![Install JavaScript on Mac Install JavaScript on Mac](/sites/tutorial2program/files/javascript-install-mac1.png)
Simply click on install, and Node will be successfully installed in your device.
![JavaScript Installation JavaScript Installation](/sites/tutorial2program/files/javascript-install-javascript-mac.png)
Step 4: Verify your installation
After the installation, you can verify whether JavaScript is installed by using the following command in the command prompt.
node --version
![JavaScript Installation Verification for Mac JavaScript Installation Verification for Mac](/sites/tutorial2program/files/javascript-installation-verify-mac.png)
Note: The version number might differ from the one above, depending on your installed version.
Now, you are all set to run JavaScript programs on your device.
Linux has various distributions, and the installation process differs slightly from each other. The following installation process is based on the Ubuntu distribution.
You need Node to use JavaScript in your device. Follow these steps to install Node on your device.
- Install VS Code
- Install Node
- Verify your installation
Here is a detailed explanation of each of the steps:
Step 1: Install VS Code
Open the Terminal and type
sudo apt update
This command updates your package lists to ensure you get the latest versions of your software.
Proceed to install VS Code with
sudo snap install code --classic
Step 2: Install Node
Go to snapcraft and click install.
![Go to Snapcraft Go to Snapcraft](/sites/tutorial2program/files/snapcraft.png)
It will give you the command to install Node.
![Get command Get command](/sites/tutorial2program/files/get-command.png)
Open your Terminal and paste the command to install Node on your device.
sudo snap install node –classic
Wait until the installation finishes to start using Node.
![JavaScript Installation for Linux JavaScript Installation for Linux](/sites/tutorial2program/files/javascript-installation-for-linux1.png)
Step 3: Verify your Installation
Once the installation is complete, you can verify whether Node is installed by using the following command in the Terminal.
node –version
![JavaScript Installation Verification for Linux JavaScript Installation Verification for Linux](/sites/tutorial2program/files/javascript-installation-verify-for-linux1.png)
Now, you are all set to run JavaScript programs on your device.
Run Your First JavaScript Program
First open VS Code, click on the File in the top menu and then select New File.
![Create a New File in VS Code Create a New File in VS Code](/sites/tutorial2program/files/new-vs-code-file1.png)
Then, save this file with a .js extension by clicking on File again, then Save As, and type your filename ending in .js. (Here, we are saving it as helloWorld.js).
Before you start coding, make sure the extension Code Runner is installed in VS Code. Open VS Code and click on Extensions on the left sidebar. Then, search for the Code Runner and click on install.
![JavaScript Extension in VSCode JavaScript Extension in VSCode](/sites/tutorial2program/files/javascript-extension-vs-code.png)
Now, write the following code into your helloWorld.js file:
console.log("Hello World")
Then click on the run button on the top right side of your screen.
![JavaScript Run Program JavaScript Run Program](/sites/tutorial2program/files/javascript-run-program1.png)
You should see Hello World! printed to the output.
Now that you have set everything up to run JavaScript programs on your computer, you'll be learning how the basic program works in JavaScript in the next tutorial.