JavaScript · Lesson 02 / 32 · English
JavaScript Get Started
Understand the idea. Change the code. Build confidence with one focused experiment.
Read this lesson in தமிழ் ↗.
Start with the idea
You can begin in a browser console or the editor below. Run a small script first, then move it into a project file. Browser page scripts can use a deferred external script so the HTML is parsed before the script runs.
Learning goal: Explain what the example does, predict its result, and change it to solve the practice task.
Step-by-step lesson notes
Running JavaScript
JavaScript runs anywhere — in the browser, on the server with Node.js, or even inside desktop apps. You don't need to install anything to get started.
1. The Browser Console
The fastest way to try JavaScript is your browser's built-in console.
- Open any browser (Chrome, Firefox, Edge)
- Press F12 (or right-click → Inspect)
- Click the Console tab
- Type JavaScript and press Enter
// Try typing this in your browser console:
console.log("Hello, World!");
2 + 2
[1,2,3].map(x => x * 2)2. JavaScript in HTML
Add JavaScript to any HTML page with a <script> tag.
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1 id="title">Hello</h1>
<!-- Always put script just before </body> -->
<script src="script.js"></script>
</body>
</html>// script.js
document.getElementById("title").textContent = "Hello from JavaScript!";3. Node.js (Server-side)
Node.js lets you run JavaScript outside the browser — on your computer or a server.
- Download Node.js from nodejs.org
- Create a file:
hello.js - Run it:
node hello.js
// hello.js
console.log("Hello from Node.js!");
console.log("Node version:", process.version);| Environment | How to run | Use case |
|---|---|---|
| Browser Console | F12 → Console tab | Quick experiments |
| HTML + Script tag | Open .html in browser | Web pages |
| Node.js | node filename.js | Server, scripts, CLIs |
| Online editors | codepen.io, jsfiddle.net | Sharing & demos |
A complete example
Run this complete index.js program in the JavaScript console editor below. The earlier reference fragments may need a browser page or other surrounding setup.
console.log("My first JavaScript session");
console.log(12 + 8);Predict first. Reveal the expected result.
My first JavaScript session 20
Make one change. See what happens.
Load the example, change a value, predict the output, and run it again. Use the console output to check your reasoning.
Wait for the editor to load, then load this example and press Run.
Powered by the free OneCompiler editor. Code you run is sent to that external service. Keep personal data and secret keys out of your examples.
Put the idea to work
Practice challenge
Print your name on one line and 7 multiplied by 6 on the next.
Reveal the answer and reasoning
Use console.log("Your name"); followed by console.log(7 * 6);. The second line is 42.
One mistake to avoid: Do not include the Console prompt symbol > when copying a command. Browser DOM APIs are not available in every JavaScript runtime.
Your learning checkpoint
- Explain the example in your own words.
- Complete the challenge before revealing its answer.
- Describe the common mistake and how to avoid it.