Visual Studio Code
Set up Visual Studio Code to write and run your JavaScript code.
Introduction
Visual Studio Code (VS Code) is one of the most popular code editors among JavaScript developers. It's lightweight, fast, and packed with powerful features that make coding easier, including syntax highlighting, extensions, and an integrated terminal.
Why Visual Studio Code?
VS Code is free, open source, supports many languages, and has a rich ecosystem of extensions tailored for JavaScript development.
Installation Steps
Download Visual Studio Code
Visit the official Visual Studio Code website and click the Download button to get the installer for your operating system (Windows, macOS, or Linux).
Run the Installer
After downloading, open the installer and follow the on-screen instructions. It is generally recommended to keep the default options.
Launch Visual Studio Code
After installation, start Visual Studio Code from your start menu or applications folder.
Install Recommended Extensions
For JavaScript, these extensions will improve your workflow:
- ESLint: Linting and code style checking
- Prettier: Code formatting
- Biome: Code linting and formatting, a newer and faster successor of eslint and prettier
- JavaScript (ES6) code snippets: Faster writing of common code
- Live Server: Instantly preview your HTML/JavaScript files in the browser with live reloading
You can find these by going to the Extensions sidebar (or press Ctrl+Shift+X) and searching for their names.
That's It!
VS Code is ready for your JavaScript projects!
First JavaScript Program
Let's write and run your very first JavaScript program in VS Code.
Create a New JavaScript File
Open VS Code and create a new file (File > New File or press Ctrl + N). Save it with a .js extension, for example: app.js.
Write Your JavaScript Code
In your new file, type a simple line of code, such as:
console.log("Hello, World!");Then save the file with Ctrl + S.
Open the Command Palette
To run the file, open the Command Palette by pressing Ctrl + Shift + P or by going to View > Command Palette.
Run the JavaScript File
In the Command Palette, search for Run JavaScript and select Run JavaScript file in terminal. This will open the terminal and run your file.
(Alternative) Run JavaScript with Node.js
You can also run your file directly in the terminal with Node.js. First, make sure Node.js is installed, then go to the folder containing your file and type:
node app.jsThis will execute your JavaScript code and show the output in the terminal.
Awesome!
That's it — you just ran your first JavaScript program in Visual Studio Code. Let's keep coding!
How is this guide?
Sign in to share your feedback
Help us improve by sharing your thoughts on this guide.
Last updated on