Set Up JavaScript Environment

๐ŸŸข Beginner

๐Ÿ“– Definition

JavaScript can run directly inside any modern web browser or in a standalone runtime environment like Node.js. Setting up your environment involves learning how to run JavaScript in the browser Developer Tools, connecting .js files to HTML documents, and running scripts using Node.js.

๐Ÿ‡ฎ๐Ÿ‡ณ Hindi

JavaScript ko aap direct browser ke Developer Console mein chalayein, ya fir .js file ko HTML document ke saath link karke chalayein. Node.js ka use karke aap JavaScript ko server-side par terminal se bhi run kar sakte hain.

๐Ÿšฉ Marathi

JavaScript tumhi browser chya Developer Console madhye direct run karu shakta, kiva .js file HTML document sobat link karun chalavu shakta. Node.js cha wapar karun terminal madhun siddhi JS code run karta yeto.

๐Ÿค” Why Use It?

Before writing JavaScript programs, you need a environment to execute your code, test ideas, debug errors, and view output in real time.

๐Ÿง  Simple Explanation

Think of the browser console as a digital notebook where you write a line of code and instantly get an answer. Linking a .js file to HTML is like attaching an engine to a carโ€”it gives the web page power and functionality.

๐Ÿ“ Setup Options

Option 1: Browser Developer Console (Fastest for testing)

1. Open Google Chrome, Firefox, or Microsoft Edge.

2. Press F12 (or right-click anywhere on a page and click Inspect).

3. Switch to the Console tab.

4. Type console.log("Hello World") and press Enter.

Option 2: Connecting JS to HTML in VS Code

Create two files in the same folder: index.html and script.js.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>JavaScript Setup</title>

<!-- defer ensures script executes after HTML parsing -->

<script src="script.js" defer></script>

</head>

<body>

<h1>JavaScript Environment Setup</h1>

</body>

</html>

/* script.js */

console.log("JavaScript file successfully connected!");

Option 3: Running JavaScript with Node.js

1. Install Node.js from nodejs.org.

2. Open your terminal or command prompt.

3. Run: node script.js

๐Ÿ’ก Important Rules & Script Placement