Beginner⏱️ 5 min📘 Topic 1 of 13

🚀 Introduction to JavaScript — What It Is & Why It Runs The Web

Learn what JavaScript is, where it runs, and why every web developer needs it. Beginner-friendly intro with examples, common myths and 5 real interview questions.

JavaScript is the programming language of the web. If a page does anything dynamic — a dropdown, a modal, fetching data, animations — that's JavaScript.

🧠 The 30-second mental model

Think of a webpage as a house:

  • HTML = the walls and rooms (structure)
  • CSS = the paint and furniture (style)
  • JavaScript = the electricity and plumbing (behavior)

Without JS, your page is a static brochure. With it, it's an app.

💡 Where does JavaScript run?

Originally only inside browsers. Today, it runs almost everywhere:

  • Browsers — Chrome, Firefox, Safari (via V8, SpiderMonkey, JavaScriptCore)
  • Servers — Node.js, Deno, Bun
  • Mobile — React Native, Ionic
  • Desktop — Electron (VS Code, Slack, Discord)

👉 Try this yourself: open any website, press F12, click "Console", type alert('Hi!') and hit Enter. You just ran JavaScript.

💻 Code Examples

Your first line of JavaScript

console.log('Hello, world!');
Output:
Hello, world!

JavaScript in an HTML page

<!DOCTYPE html>
<html>
  <body>
    <button onclick="alert('Clicked!')">Click me</button>
  </body>
</html>
Output:
Renders a button. Clicking shows an alert popup.

⚠️ Common Mistakes

  • Confusing JavaScript with Java — they share a name and almost nothing else.
  • Thinking JavaScript only runs in browsers (Node.js powers half the backend world).
  • Assuming JavaScript is just for 'simple scripts' — large apps like Figma, Notion, and Gmail are built on it.

🎯 Interview Questions

Real questions asked at top product and service-based companies.

Q1.Is JavaScript a compiled or interpreted language?Beginner
Technically both. Modern engines like V8 use JIT (Just-In-Time) compilation — your code is parsed, then compiled to optimized machine code as it runs. You don't compile it ahead of time like C++, so it feels interpreted.
Q2.What's the difference between JavaScript and ECMAScript?Beginner
ECMAScript (ES) is the language specification. JavaScript is the most popular implementation of that spec. When people say 'ES6', they mean ECMAScript 2015 — the spec version JavaScript follows.
Q3.Is JavaScript single-threaded or multi-threaded?Beginner
Single-threaded — it has one call stack. But it achieves concurrency via the event loop and async APIs (setTimeout, fetch, Promises) handled by the browser/Node runtime.
Q4.What's the difference between client-side and server-side JavaScript?Intermediate
Client-side runs in the browser, has access to DOM/window but no file system. Server-side runs in Node.js (or similar), has file system and OS access but no DOM. Same language, different APIs.
Q5.Can I run JavaScript without a browser?Beginner
Yes — Node.js, Deno, and Bun all let you run JS files from the command line: `node script.js`.

🧠 Quick Summary

  • JavaScript = the language that makes websites interactive.
  • Single-threaded, event-loop based, JIT-compiled at runtime.
  • Runs everywhere: browsers, servers (Node.js), mobile, desktop.
  • Not the same as Java — only the name is similar.
  • ECMAScript is the spec; JavaScript is the implementation.