NelsonLabs
JavaScript Basics/What is JavaScript?

What is JavaScript?

JavaScript is the only programming language that runs natively inside every web browser. It's what makes websites interactive — clicks that do things, forms that validate, content that updates without a page reload.

ANALOGY

HTML is the building, CSS is the decoration, JavaScript is the electricity. HTML structures the content. CSS makes it look good. JavaScript makes it work — it's the power that turns a static mockup into a working application. Every button click, live search, and real-time notification you've ever experienced online was JavaScript.

Where JavaScript runs

  • Browser — JavaScript originally lived here, making web pages interactive. Every browser has a JS engine built in.
  • Server — Node.js lets JavaScript run on servers, handling databases, APIs, and backend logic.
  • Mobile — React Native and other frameworks use JavaScript to build iOS and Android apps.
  • Desktop — Electron lets you build desktop apps with JavaScript (VS Code is built this way).
Your first JavaScript
javascript
// This is a comment — the engine ignores it
// Two slashes start a single-line comment

/* This is a multi-line comment
   Also ignored by the engine */

// Print something to the browser console
console.log("Hello, World!");

// Store a value in a variable
let name = "Nelson";

// Use the variable
console.log("Hello, " + name + "!");
// Output: Hello, Nelson!

// JavaScript can do maths
let total = 5 * 12;
console.log(total);  // 60

How to run JavaScript

  • Browser Console — Press F12 (or Cmd+Option+I on Mac), go to Console, and type JavaScript directly.
  • HTML script tag — Add <script src="app.js"></script> to your HTML, or inline with <script>...</script>.
  • Node.js — In your terminal: node filename.js.