Intermediate–Advanced 15 terms

JavaScript & TypeScript

Core language concepts explained in plain English — closures, async patterns, TypeScript types, and modern syntax.

  • Closure /ˈkləʊʒər/

    A function that retains access to its outer scope even after the outer function has returned.

    "The counter function uses a closure — each call to makeCounter() creates an independent count variable that persists."
  • Hoisting /ˈhɔɪstɪŋ/

    JavaScript's behaviour of moving variable and function declarations to the top of their scope before execution.

    "The bug was caused by hoisting — the var was accessible before its assignment, returning undefined."
  • Promise /ˈprɒmɪs/

    An object representing the eventual completion or failure of an asynchronous operation, with .then()/.catch() chaining.

    "We chain .then() calls on the fetch Promise to parse the JSON and update the UI after the request resolves."
  • async / await /eɪˈsɪŋk / əˈweɪt/

    Syntax sugar over Promises that lets you write asynchronous code that reads like synchronous code.

    "Using async/await makes the data-fetching logic much easier to read — no more nested callbacks or .then() chains."
  • Type Narrowing /taɪp ˈnærəʊɪŋ/

    TypeScript's mechanism of refining a type within a conditional block using typeof, instanceof, or discriminant properties.

    "After the typeof check, TypeScript narrows the type from string | number to string, enabling string methods."
  • Generics /dʒɪˈnerɪks/

    A way to create reusable components that work with any type, defined with type parameters like <T>.

    "The getFirst<T>(arr: T[]): T function is generic — it preserves the exact type of the array element it returns."
  • Destructuring /diːˈstrʌktʃərɪŋ/

    Syntax for unpacking values from arrays or properties from objects into distinct variables.

    "We use destructuring in the function signature: ({ userId, role }) => ... to avoid accessing props.userId repeatedly."
  • Rest / Spread /rest / spred/

    Rest (...args) collects remaining elements; spread (...arr) expands an iterable into individual elements.

    "Spread merges two objects: const merged = { ...defaults, ...overrides }. Rest captures extra args: function log(msg, ...meta)."
  • Type Guard /taɪp ɡɑːd/

    A function whose return type is a type predicate (x is SomeType) that tells TypeScript what type a value is at runtime.

    "The isUser type guard checks for the presence of .userId so TypeScript knows the type inside the if-block."
  • Interface vs Type /ˈɪntəfeɪs vəs taɪp/

    Both define object shapes. Interfaces are extendable via declaration merging; types can express unions, intersections, and primitives.

    "We use interface for public API contracts because it can be extended by consumers; type alias for complex union types internally."
  • Union Type /ˈjuːnjən taɪp/

    A type formed with | that allows a value to be one of several types: string | number | null.

    "The API response ID is typed as string | number because legacy records use integers and new ones use UUIDs."
  • Optional Chaining /ˈɒpʃənl ˈtʃeɪnɪŋ/

    The ?. operator that short-circuits property access if the value to the left is null or undefined.

    "Using user?.profile?.avatar prevents a TypeError if profile is undefined — returns undefined instead of throwing."
  • Nullish Coalescing /ˈnʌlɪʃ kəʊˈælesɪŋ/

    The ?? operator returns the right-hand side only when the left-hand side is null or undefined (not falsy).

    "timeout ?? 5000 returns 5000 only if timeout is null/undefined — unlike ||, it won't replace 0 with the default."
  • Utility Types /juːˈtɪlɪti taɪps/

    Built-in TypeScript generic types for transforming other types: Partial<T>, Required<T>, Pick<T,K>, Readonly<T>, Record<K,V>.

    "We use Partial<UserSettings> as the parameter type for the update function so only provided fields are required."
  • Event Loop /ɪˈvent luːp/

    The mechanism that processes the call stack, microtask queue (Promises), and macrotask queue (setTimeout) in order.

    "Understanding the event loop explains why console.log after an awaited Promise always runs before setTimeout callbacks."

Ready to practice?

Test your knowledge of these terms in the interactive exercise.

Start exercise →