MDN self-hosted library · e01.org

JavaScript language overview

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
console.log(3 / 2); // 1.5, not 1
js
console.log(0.1 + 0.2); // 0.30000000000000004
js
console.log(0b111110111); // 503
console.log(0o767); // 503
console.log(0x1f7); // 503
console.log(5.03e2); // 503
js
console.log(-3n / 2n); // -1n
js
Math.sin(3.5);
const circumference = 2 * Math.PI * r;
js
console.log("Hello, world");
console.log("你好,世界!"); // Nearly all Unicode characters can be written literally in string literals
js
console.log("Hello"[1] === "e"); // true
js
const age = 25;
console.log("I am " + age + " years old."); // String concatenation
console.log(`I am ${age} years old.`); // Template literal
js
Boolean(""); // false
Boolean(234); // true
js
let a;
let name = "Simon";

// myLetVariable is *not* visible out here

for (let myLetVariable = 0; myLetVariable < 5; myLetVariable++) {
  // myLetVariable is only visible in here
}

// myLetVariable is *not* visible out here
js
const Pi = 3.14; // Declare variable Pi
console.log(Pi); // 3.14