Content & privacy
Languages · INTERVIEW GUIDE

JavaScript & TypeScript

Scope, closures, async behavior, object identity, and the type system.

Practice this topic
Filters
27 questions

How do garbage collection and memory leaks work?

JavaScript & TypeScript·Runtime & modules

Garbage collection automatically reclaims memory that can no longer be reached by running code. A memory leak happens when the program keeps a reference to data it no longer needs, so the collector must treat that data as still usable. Increasing the heap limit may delay failure but does not remove the unwanted references.

Intermediate2 min read

Interface vs type: which should I use?

JavaScript & TypeScript·TypeScript

Interfaces and type aliases both describe types that TypeScript checks before runtime. An interface is mainly used for object contracts, while a type alias can name object shapes, unions, tuples and other type expressions. Choosing between them is mostly about the shape being modeled and whether declaration merging is needed.

Intermediate2 min read

What are generics and utility types?

JavaScript & TypeScript·TypeScript

Generics let a function, class or type work with different types while preserving relationships between inputs and outputs. Utility types transform existing types so the same fields do not need to be manually repeated. This reduces duplication without throwing away type information through any.

Intermediate2 min read

What are union, intersection, keyof and typeof?

JavaScript & TypeScript·TypeScript

A union allows a value to match one of several types, while an intersection requires it to satisfy all included types. keyof extracts property names from a type, and TypeScript's type-position typeof derives a type from a value declaration. Together they help express safe property access and reusable contracts.

Intermediate2 min read

What are unknown, any and never?

JavaScript & TypeScript·TypeScript

any allows operations without normal type checking, while unknown accepts any value but requires checks before use. never represents a situation where no value is possible, such as the result of a function that always throws. These types describe different levels of knowledge and should not be used interchangeably.

Intermediate2 min read

How do narrowing and type guards work?

JavaScript & TypeScript·TypeScript

Narrowing is TypeScript's process of reducing a broad type to a more specific type based on control flow and checks. A type guard is a check that gives the compiler evidence about a value, such as typeof, in or a custom predicate. Correct guards help application code safely use data that starts out uncertain.

Intermediate2 min read

What are mapped types, conditional types and decorators?

JavaScript & TypeScript·TypeScript

Mapped types build a new type by visiting the keys of another type, and conditional types choose a type based on a type relationship. Decorators are different: they run as part of JavaScript class definition and can add metadata or change behavior. Type transformations disappear during compilation, while decorator code can affect runtime behavior.

Intermediate2 min read

What is the output here?

JavaScript & TypeScript·Output prediction

Output prediction requires following the order in which synchronous code and queued callbacks can execute. This example combines the current script, a promise microtask and a timer callback. A zero-delay timer becomes eligible later; it does not interrupt the running script.

Intermediate2 min read

Why does a var loop print 3 three times?

JavaScript & TypeScript·Output prediction

The var loop creates one shared function-scoped binding for i. Every callback closes over that same binding, and the loop has already set it to 3 before the timer callbacks run. Using let in the loop header creates a separate binding for each iteration.

Intermediate2 min read

Difficulty is an editorial estimate. Completion means you chose to mark a question as understood.