Setup & Running JavaScript
Learn how to set up your environment and run JavaScript using the browser, HTML files, and browser developer tools.
Reading Time
10 min
Lesson
Lesson 2 of 48
Do You Need to Install JavaScript?
No. JavaScript comes built into every modern web browser such as Chrome, Edge, Firefox, and Safari. You only need a browser and a code editor like Visual Studio Code to start learning.
Tools Required
- Google Chrome (Recommended)
- Visual Studio Code
- Basic knowledge of HTML
Method 1: Run JavaScript Using the Browser Console
The fastest way to practice JavaScript is by using the browser Developer Console. It allows you to execute JavaScript instantly without creating any files.
Example
Console Output
Click “Run” to see the console output here.
How to Open the Console
Press F12 or Ctrl + Shift + I (Windows/Linux) or Cmd + Option + I (Mac), then open the Console tab.
Method 2: Run JavaScript Inside an HTML File
JavaScript is commonly written inside HTML files using the <script> tag.
index.html
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Demo</title>
</head>
<body>
<h1>Hello JavaScript</h1>
<script >
console.log("Welcome to DevAcademy");
</script>
</body>
</html>Method 3: External JavaScript File
In real-world projects, JavaScript is usually written in separate .js files and linked to the HTML document.
index.html (External Script)
<script src="script.js"></script>script.js
Console Output
Click “Run” to see the console output here.
Why Use External Files?
Keeping JavaScript in separate files improves code organization, readability, and reusability. This is the standard practice in professional projects.
Method 4: Using Visual Studio Code
Visual Studio Code is one of the most popular code editors for JavaScript development. Create an HTML file and a JavaScript file, write your code, and open the HTML file in a browser to see the output.
Steps
- Create a new folder.
- Create index.html.
- Create script.js.
- Link script.js using the script tag.
- Open index.html in your browser.
- Check the output in the browser console.
Common Mistakes
Many beginners forget to link the JavaScript file correctly or use the wrong file name. Always ensure the src attribute matches the actual file name.
Ways to Run JavaScript
| Method | Best For |
|---|---|
| Browser Console | Quick Testing |
| HTML Script Tag | Learning Basics |
| External JS File | Real Projects |
| Node.js | Backend Development |
Best Practice
Use the browser console to experiment with small code snippets, but use external JavaScript files when building applications.
Summary
JavaScript can run directly in the browser without installation. During development, developers usually write JavaScript in external files and use browser developer tools for debugging.