What is JavaScript?
JavaScript is the programming language of the web. Every website you visit uses JavaScript to create interactive experiences — from dropdown menus and form validation to complex web applications like Gmail, YouTube, and Google Maps.
Unlike Python which runs on your computer, JavaScript was originally designed to run inside web browsers. Today it also runs on servers (Node.js), mobile apps, and desktop applications.
Despite the similar name, JavaScript and Java are completely different languages. JavaScript was named during the 1990s when Java was popular — it was a marketing decision, not a technical one.
Where JavaScript Runs
- Browser: Every modern browser has a built-in JavaScript engine (Chrome uses V8, Firefox uses SpiderMonkey)
- Server: Node.js lets you run JavaScript outside the browser
- Mobile: React Native and similar frameworks build mobile apps with JavaScript
- Desktop: Electron framework powers apps like VS Code and Discord
Your First JavaScript
Method 1: Browser Console (Fastest)
console.log("Hello, World!");
Press Enter and you'll see Hello, World! printed below. The console is
JavaScript's equivalent of Python's interactive shell.
// Try some more
console.log(2 + 3); // 5
console.log("JavaScript" + " rocks"); // JavaScript rocks
alert("Welcome!"); // Shows a popup dialog
Method 2: HTML File
JavaScript is typically embedded in HTML pages. Create a file called index.html:
<!DOCTYPE html>
<html>
<head>
<title>My First JS Page</title>
</head>
<body>
<h1 id="greeting">Hello!</h1>
<button onclick="changeText()">Click Me</button>
<script>
function changeText() {
document.getElementById("greeting").textContent = "You clicked the button!";
}
</script>
</body>
</html>
Open this file in your browser and click the button — the heading text changes! This is JavaScript manipulating the page in real time.
JavaScript vs Python: Key Differences
// JavaScript uses:
let name = "Alice"; // let/const for variables (not just name = )
console.log(name); // console.log (not print)
// Semicolons at end of lines (optional but recommended)
// Curly braces {} for code blocks (not indentation)
// camelCase naming (not snake_case)
// Python equivalent:
// name = "Alice"
// print(name)
Comments
// Single-line comment
/* Multi-line
comment */
// Comments are ignored by JavaScript
// Use them to explain your code
The console Object
console.log("Regular message"); // Standard output
console.warn("Warning message"); // Yellow warning
console.error("Error message"); // Red error
console.table(["apple", "banana"]); // Display as table
console.time("timer");
// ...some code...
console.timeEnd("timer"); // Shows elapsed time
Summary
- JavaScript is the language of the web — it makes pages interactive
- It runs in browsers, servers (Node.js), mobile apps, and desktop apps
- Use the browser console (F12) for quick experiments
console.log()is JavaScript's version ofprint()- JavaScript uses
let/constfor variables, curly braces for blocks, and camelCase naming
You've written your first JavaScript code. In the next tutorial, you'll learn about variables, data types, and how JavaScript handles different kinds of data.