JavaScript Interview

Closures, Prototypes, Classes & Advanced Functions

JavaScript interview questions covering closures, IIFEs, prototypes, prototype chains, constructors, classes, inheritance, advanced functions and object-oriented JavaScript.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
101
Mid-LevelIntermediate

What is a closure in JavaScript?

A closure is created when a function retains access to variables from its lexical scope even after the outer function has finished executing. The inner function keeps a reference to the required surrounding environment rather than receiving a one-time copy of each value.

102
Mid-LevelIntermediate

What are practical uses of closures?

Closures are useful whenever a function needs to remember state from the environment in which it was created. Common examples include counters, configuration factories, encapsulated state, partially configured functions, event handlers, and caching.

103
Mid-LevelIntermediate

What is an IIFE in JavaScript?

An IIFE, or Immediately Invoked Function Expression, is a function expression that executes immediately after it is created. Before ES modules and block-scoped declarations became common, IIFEs were frequently used to create a private scope and avoid leaking variables into the global scope.

104
Mid-LevelIntermediate

What is the prototype in JavaScript?

JavaScript objects can have an internal link to another object called their prototype. When a property is not found directly on an object, JavaScript can search its prototype and continue through the prototype chain.

105
Mid-LevelIntermediate

What is the prototype chain?

The prototype chain is the sequence of prototype links JavaScript follows when resolving a property. It starts with the object itself, then continues through its prototype, that prototype's prototype, and so on until a matching property is found or the chain reaches null.

106
Mid-LevelIntermediate

What is the difference between an own property and an inherited property?

An own property belongs directly to the object, while an inherited property is found through the object's prototype chain. The in operator checks both own and inherited properties.

107
Mid-LevelIntermediate

What does the new operator do in JavaScript?

When used with a constructable function or class, new creates a new object, links it to the constructor's prototype, calls the constructor with this bound to the new object, and normally returns that object.

108
Mid-LevelIntermediate

What are constructor functions?

A constructor function is an ordinary constructable function intended to create objects when called with new. By convention its name begins with a capital letter.

109
Mid-LevelIntermediate

What are JavaScript classes?

JavaScript classes provide structured syntax for creating constructor/prototype-based object types. A class can contain a constructor, instance methods, static members, fields, getters, setters, and inheritance declarations.

110
Mid-LevelIntermediate

How does inheritance work with extends and super?

The extends keyword creates a derived class whose instances inherit behavior from the base class. In a derived constructor, super must be called before accessing this because it initializes the base portion of the instance.

111
Mid-LevelIntermediate

What are static methods and static fields in JavaScript classes?

Static members belong to the class constructor itself rather than to individual instances. They are useful for utility behavior, factories, counters, configuration, or operations conceptually related to the class but not dependent on a particular instance.

112
Mid-LevelIntermediate

What are private class fields in JavaScript?

Private class fields use names beginning with # and can be accessed only from code inside the declaring class. They provide language-enforced encapsulation rather than relying only on naming conventions.

113
Mid-LevelIntermediate

What are getters and setters?

Getters and setters define property-like access backed by functions. A getter runs when the property is read, while a setter runs when the property is assigned.

114
Mid-LevelIntermediate

What do call(), apply(), and bind() do?

call and apply invoke a function immediately with an explicitly supplied this value. call receives function arguments individually, while apply receives them in an array or array-like collection.

115
Mid-LevelIntermediate

What is function currying?

Currying transforms a function that accepts multiple arguments into a sequence of functions that each accept one argument. It is a functional-programming technique for creating reusable, partially configured operations.

116
Mid-LevelIntermediate

What is a higher-order function?

A higher-order function takes one or more functions as arguments, returns a function, or both. JavaScript supports this naturally because functions are first-class values.

117
Mid-LevelIntermediate

What does it mean that functions are first-class citizens in JavaScript?

Functions are first-class values, meaning they can be stored in variables and object properties, passed as arguments, returned from other functions, and placed in data structures.

118
Mid-LevelIntermediate

What is recursion in JavaScript?

Recursion occurs when a function calls itself, directly or indirectly, until a base condition stops further calls. It is useful for naturally recursive structures such as trees, nested menus, directory structures, and certain algorithms.

119
Mid-LevelIntermediate

What is memoization?

Memoization is an optimization technique that caches the result of a function for previously seen inputs so repeated calls can reuse the cached result instead of recalculating it.

120
Mid-LevelIntermediate

What is debouncing?

Debouncing delays a function until a specified quiet period has passed since the most recent call. Repeated calls reset the timer, so only the final call after activity stops is normally executed.

121
Mid-LevelIntermediate

What is throttling?

Throttling limits how frequently a function can execute during a period of continuous calls. Unlike debouncing, throttling can continue producing results at controlled intervals while the activity is still happening.

122
Mid-LevelIntermediate

What is the difference between debouncing and throttling?

Debouncing waits until calls stop for a specified delay and then normally runs once. Throttling allows execution at a limited frequency while calls continue.

123
Mid-LevelIntermediate

What are property descriptors in JavaScript?

Each ordinary object property has metadata describing characteristics such as value, writable, enumerable, and configurable. Accessor properties instead use get and set descriptors.

124
Mid-LevelIntermediate

What are Symbol values used for?

A Symbol is a primitive value that is guaranteed to be unique when created with Symbol(). Symbols can be used as object property keys without colliding with ordinary string keys.

125
Mid-LevelIntermediate

What are iterables and iterators in JavaScript?

An iterable is an object that implements the iterable protocol by providing a method at Symbol.iterator. That method returns an iterator. An iterator exposes a next method that returns objects containing value and done.