Skip to content

JavaScript Tutorial JavaScript Practice Reference

JavaScript Quick Reference

Lesson 258 of 258 3 min read By Deepak Paswan Updated Oct 4, 2026

A compact reference for what the course teaches. For details, follow the links.

Variables and types

TaskCode
Constant / changing valueconst x = 1; / let y = 2; (let and const)
Typesstring, number, bigint, boolean, undefined, null, symbol, object
Check typetypeof x, Array.isArray(x)
Default if null or undefinedx ?? "default" (??)
Safe property accessuser?.address?.city (?.)
Strict equalitya === b (equality)

Strings

TaskCode
Template literaltext between backticks with ${name} placeholders (template literals)
Searchs.includes("a"), s.startsWith("a"), s.indexOf("a")
Cuts.slice(0, 3), s.trim(), s.padStart(5, "0")
Replace and splits.replaceAll("a", "b"), s.split(",")

Arrays

TaskCode
Add / remove at endpush(x) / pop()
Transformmap(fn) (map)
Keep somefilter(fn) (filter)
Combine to one valuereduce(fn, start) (reduce)
Findfind(fn), findIndex(fn), includes(x), some(fn), every(fn)
Sort a copy[...a].sort((x, y) => x - y) or a.toSorted(...)
Copy / merge[...a], [...a, ...b]
Unpackconst [first, ...rest] = list

Objects

TaskCode
Keys, values, entriesObject.keys(o), Object.values(o), Object.entries(o)
Copy / merge{ ...a, ...b } (spread)
Unpackconst { name, age = 18 } = user
Has own propertyObject.hasOwn(o, "key")
Deep copystructuredClone(o)

Functions

TaskCode
Arrow functionconst add = (a, b) => a + b; (arrows)
Default / restfunction f(a = 1, ...rest) {}
Callbackitems.forEach(item => ...)
Closurea function that remembers outer variables (closures)

DOM and events

TaskCode
Selectdocument.querySelector(".x"), querySelectorAll(".x") (selecting)
Text / HTMLel.textContent = "..." (safe), el.innerHTML (careful)
Classesel.classList.add("a"), .toggle("a") (classList)
Create and adddocument.createElement("li"), parent.append(el)
Listenel.addEventListener("click", fn) (addEventListener)
Delegatelist.addEventListener("click", e => e.target.closest("li")) (delegation)
Stop defaultevent.preventDefault()
Data attributesel.dataset.id

Async and fetch

script.js
JS
const wait = ms => new Promise(r => setTimeout(r, ms));

async function load(url) {
  try {
    const response = await fetch(url);
    if (!response.ok) throw new Error("HTTP " + response.status);
    return await response.json();
  } catch (error) {
    console.error(error);
    return null;
  }
}
TaskCode
All must succeedawait Promise.all([a(), b()]) (Promise.all)
Handle each resultawait Promise.allSettled([...])
Cancel / timeoutAbortController, AbortSignal.timeout(ms) (abort)

JSON and storage

TaskCode
Object to text / backJSON.stringify(o) / JSON.parse(text) (JSON)
Save / readlocalStorage.setItem(k, v) / getItem(k) (storage)

Errors

script.js
JS
try { risky(); } catch (error) { console.error(error.message); } finally { cleanUp(); }
throw new Error("Something went wrong");

Modules

script.js
JS
export const PI = 3.14;
export default class Logger {}
import Logger, { PI } from "./lib.js";
const module = await import("./lazy.js");

Where to look things up

MDN Web Docs is the best reference for every method, with compatibility tables. The lessons in this course explain the ideas, and MDN gives the complete details.