This chapter is a quick-reference guide to JavaScript’s core types, operators, built-in objects, and methods. Use it as a cheat sheet when writing code or preparing for interviews.
| Type | Example | typeof |
|---|---|---|
| Number | 42, 3.14 | "number" |
| String | "hello", 'world' | "string" |
| Boolean | true, false | "boolean" |
| Undefined | undefined | "undefined" |
| Null | null | "object" |
| BigInt | 9007199254740991n | "bigint" |
| Symbol | Symbol("id") | "symbol" |
| Object | {a:1}, [1,2] | "object" |
| Category | Operators |
|---|---|
| Arithmetic | + - * / % ** ++ -- |
| Assignment | = += -= *= /= %= **= |
| Comparison | == === != !== > < >= <= |
| Logical | && || ! ?? |
| Bitwise | & | ^ ~ << >> >>> |
| Ternary | condition ? expr1 : expr2 |
| Spread / Rest | ...arr |
class Animal {
constructor(name) { this.name = name; }
speak() { console.log(`${this.name} makes a sound.`); }
static classify() { return 'Mammal'; }
}
class Dog extends Animal {
constructor(name, breed) {
super(name);
this.breed = breed;
}
speak() { console.log(`${this.name} barks.`); }
}
// Iteration
arr.forEach(fn); arr.map(fn); arr.filter(fn); arr.reduce(fn, init); arr.some(fn); arr.every(fn);
// Mutation
arr.push(v); arr.pop(); arr.shift(); arr.unshift(v); arr.splice(i, n); arr.sort(fn); arr.reverse();
// Access / search
arr.concat(arr2); arr.slice(i, j); arr.indexOf(v); arr.find(fn); arr.findIndex(fn); arr.flat(depth);
// Static
Array.from(iterable); Array.of(v1, v2, ...); Array.isArray(v);
"hello".toUpperCase(); "HELLO".toLowerCase();
"hello".trim(); "hello".charAt(0); "hello".indexOf("e");
"hello".slice(1, 4); "hello".split(""); "hello".includes("ell");
"hello".startsWith("he"); "hello".endsWith("lo");
"hello".replace("l", "x"); "hello".repeat(3);
"a,b,c".split(","); "hello".padStart(10, "*");
Number.isNaN(v); Number.isInteger(v); Number.parseFloat("3.14"); Number.parseInt("42", 10);
Number(v).toFixed(2);
Math.round(3.7); Math.floor(3.7); Math.ceil(3.2);
Math.min(1, 5, 3); Math.max(1, 5, 3);
Math.random(); // 0 to < 1
Math.abs(-5); Math.pow(2, 3); Math.sqrt(16); Math.PI;
const d = new Date();
d.getFullYear(); d.getMonth(); d.getDate(); d.getDay();
d.getHours(); d.getMinutes(); d.getSeconds();
d.toISOString(); d.toLocaleDateString(); d.toLocaleTimeString();
// Setting
d.setFullYear(2025); d.setMonth(11); d.setDate(25);
// Timestamp
Date.now(); d.getTime();
All examples in this tutorial target modern browsers (Chrome, Firefox, Safari, Edge). For older browser support, use caniuse.com to check feature availability and consider transpilers like Babel and polyfills like core-js.
Create an interactive HTML page that displays all Array methods. For each method, show its syntax, a short description, and a clickable “Run Example” button that logs the result to the console. Use the data-* attributes to store the method name and parameters.