⚙️ JavaScript Setup
Last Updated: 01 Oct 2025
To start writing and running JavaScript, we need to understand file extension, tools, and different ways to run JS code.
📂 File Extension
- JavaScript files are saved with
.jsextension. - Example:
script.js,app.js
🖥 Ways to Run JavaScript
1. Browser Console (Quick Test)
- Open any browser → Press F12 → Go to Console Tab.
- Type code directly:
console.log("Hello from JS Console!");
2. Inline Script in HTML
Write JS directly inside <script> tag in an HTML file:
<!DOCTYPE html>
<html>
<head>
<title>JS Inline Script</title>
</head>
<body>
<h1>Hello JavaScript!</h1>
<script>
console.log("This is inline JavaScript");
</script>
</body>
</html>
3. External Script File
Save code in script.js. Link it inside HTML:
<!DOCTYPE html>
<html>
<head>
<title>JS External File</title>
</head>
<body>
<h1>Hello External JS!</h1>
<script src="script.js"></script>
</body>
</html>
Note: Use of
deferAttribute in<script>Tag.
Normally, when you add a <script> tag in HTML, the browser stops loading the page until the script finishes.
<script src="script.js" defer></script>
To avoid this blocking, we can use defer.
It work like this:
- Script loads in background while HTML continues parsing.
- Script executes after the HTML is fully loaded
- Keeps the correct order if multiple scripts have defer.
4. Node.js
- Download & Install Node.js.
- Save code in
script.js. - Run
node script.jsin terminal.