Code Reference

Hello World

JavaScript · Reference cheat sheet

Hello World

JavaScript · Reference cheat sheet


📋 Overview

Hello World confirms your JS environment works. The usual first call is console.log, which writes to the browser console or the terminal (Node).

🔧 Core concepts

PieceRole
console.log(...)Print values for humans / debugging
String literal"text" or 'text' or `text`
StatementAn instruction, often ending with ; (ASI may insert them)
ScriptCode loaded by Node or a browser

Semicolons are recommended for beginners even though Automatic Semicolon Insertion exists.

💡 Examples

Node script:

console.log("Hello, World!");
node hello.js

Multiple values:

const name = "Ada";
console.log("Hello,", name);
console.log(`Hello, ${name}!`);

Browser alert (UI, not for real apps):

alert("Hello, World!");

Log different types:

console.log(42);
console.log(true);
console.log({ ok: true });
console.log(["a", "b"]);

⚠️ Pitfalls

  • In the browser, look at the Console tab — not the page body — for console.log.
  • alert blocks the UI; use it sparingly while learning.
  • Smart quotes from documents break string literals.
  • Running TypeScript (.ts) needs a toolchain; plain Hello World should be .js.

On this page