Master JavaScript Interviews with This Curated List of 1000 Questions that Help You Prepare for Any Frontend or Full-Stack Role ๐
Repo codeaashu/javascript-interview-questions, read from GitHub 1 min ago. codeaashu has not joined Take My Repo.
codeaashu/javascript-interview-questions is a public repo on GitHub by codeaashu. Master JavaScript Interviews with This Curated List of 1000 Questions that Help You Prepare for Any Frontend or Full-Stack Role ๐. It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it. It is written mainly in JavaScript, has 13 stars and last changed on 2026-08-29. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-18.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Click โญif you like the project and connect with us on aashuu for more updates. Coding questions available here. Check DataStructures and Algorithms for DSA related questions and ECMAScript for all ES features.).
There are many ways to create objects in javascript as mentioned below:
Object literal syntax:
The object literal syntax (or object initializer), is a comma-separated set of name-value pairs wrapped in curly braces.
var object = { name: "aashuu", age: 34, };
Object literal property values can be of any data type, including array, function, and nested object.
Note: This is one of the easiest ways to create an object and it's most commonly used for creating simple, ad-hoc objects.
Object constructor:
The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended.
var object = new Object();
The Object() is a built-in constructor function so "new" keyword is not required for creating plain objects. The above code snippet can be re-written as:
var object = Object();
However, Object() can be used to either create a plain object or convert a given value into its corresponding object wrapper, whereas new Object() is specifically used to explicitly create a new object instance.
Object's create method:
The create method of Object is used to create a new object by passing the specified prototype object and properties as arguments, i.e., this pattern is helpful to create new objects based on existing objects. In other words, this is useful for setting up prototypal inheritance. The second argument is optional and it is used to create properties on a newly created object.
The following code creates a new empty object whose prototype is null.
var object = Object.create(null);
The following example creates an object along with additional new properties.
let vehicle = { wheels: "4", fuelType: "Gasoline", color: "Green", }; let carProps = { type: { value: "Volkswagen", }, model: { value: "Golf", }, }; var car = Object.create(vehicle, carProps); console.log(car);
Function constructor:
In this approach, create any function and apply the new operator to create object instances. This was the main way to do constructor-based OOP before ES6 classes.
function Person(name) { this.name = name; this.age = 21; } var object = new Person("Ashutosh");
Function constructor with prototype:
This is similar to function constructor but it uses prototype for their properties and methods. Using prototype means you're sharing methods/properties across instances, which saves memory and improve performance.
function Person() {} Person.prototype.name = "Ashutosh"; var object = new Person();
This is equivalent to creating an instance with Object.create method with a function prototype and then calling that function with an instance and parameters as arguments.
function func(x, y, z) { this.x = x; this.y = y; this.z = z; } var instance = new func(1, 2, 3);
(OR)
function func(x, y, z) { this.x = x; this.y = y; this.z = z; } // Create a new instance using function prototype. var newInstance = Object.create(func.prototype) // Call the function var result = func.call(newInstance, 1, 2, 3), // If the result is a non-null object then use it otherwise just use the new instance. console.log(result && typeof result === 'object' ? result : newInstance);
Object's assign method:
The Object.assign method is used to copy all the properties from one or more source objects and stores them into a target object. This is mainly used for cloning and merging
The following code creates a new staff object by copying properties of his working company and the car he owns.
const orgObject = { company: "XYZ Corp" }; const carObject = { name: "Toyota" }; const staff = Object.assign({}, orgObject, carObject);
ES6 Class syntax:
ES6 introduces class feature to create objects. This is syntactic sugar over the prototype-based system.
class Person { constructor(name) { this.name = name; } } var object = new Person("Ashutosh");
Singleton pattern:
A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance. This way one can ensure that they don't accidentally create multiple instances.
const Singleton = (function () { let instance; function createInstance() { return { name: "aashuu" }; } return { getInstance: function () { if (!instance) { instance = createInstance(); } return instance; } }; })(); // Usage const obj1 = Singleton.getInstance(); const obj2 = Singleton.getInstance(); console.log(obj1 === obj2); // true
In modern JavaScript applications, singletons are commonly implemented using ES6 modules for their built-in caching behavior, or closures for encapsulated state management.
The prototype chain is a core concept in JavaScriptโs inheritance model. It allows objects to inherit properties and methods from other objects. When you try to access a property or method on an object, JavaScript first looks for it on that object itself. If itโs not found, the engine looks up the object's internal [[Prototype]] reference (accessible via Object.getPrototypeOf(obj) or the deprecated __proto__ property) and continues searching up the chain until it finds the property or reaches the end (usually null).
For objects created via constructor functions, the prototype chain starts with the instance, then refers to the constructorโs .prototype object, and continues from there. For example:
function Person() {} const person1 = new Person(); console.log(Object.getPrototypeOf(person1) === Person.prototype); // true
This mechanism allows for property and method sharing among objects, enabling code reuse and a form of inheritance.
Summary:
Object.getPrototypeOf(obj) or __proto__.Constructor.prototype.null.The prototype chain among objects appears as below,
call, apply, and bindIn JavaScript, call, apply, and bind are methods that allow you to control the context (this value) in which a function is executed. While their purposes are similar, they differ in how they handle arguments and when the function is invoked.
callDescription:
The call() method invokes a function immediately, allowing you to specify the value of this and pass arguments individually (comma-separated).
Syntax:
func.call(thisArg, arg1, arg2, ...)
Example:
var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you? invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?
applyDescription:
The apply() method is similar to call(), but it takes the function arguments as an array (or array-like object) instead of individual arguments.
Syntax:
func.apply(thisArg, [argsArray])
Example:
var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } invite.apply(employee1, ["Hello", "How are you?"]); // Hello John Rodson, How are you? invite.apply(employee2, ["Hello", "How are you?"]); // Hello Jimmy Baily, How are you?
bindDescription:
The bind() method creates a new function with a specific this value and, optionally, preset initial arguments. Unlike call and apply, bind does not immediately invoke the function; instead, it returns a new function that you can call later.
Syntax:
var boundFunc = func.bind(thisArg[, arg1[, arg2[, ...]]])
Example:
var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" }; function invite(greeting1, greeting2) { console.log( greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2 ); } var inviteEmployee1 = invite.bind(employee1); var inviteEmployee2 = invite.bind(employee2); inviteEmployee1("Hello", "How are you?"); // Hello John Rodson, How are you? inviteEmployee2("Hello", "How are you?"); // Hello Jimmy Baily, How are you?
| Method | Invokes Function Immediately? | How Arguments Are Passed | Returns |
|---|---|---|---|
call |
Yes | Comma-separated list | Function's result |
apply |
Yes | Array or array-like object | Function's result |
bind |
No | (Optional) preset, then rest | New function |
call and apply are almost interchangeable; both invoke the function immediately, but differ in how arguments are passed.
bind does not execute the function immediately. Instead, it creates a new function with the specified this value and optional arguments, which can be called later.
Use call or apply when you want to immediately invoke a function with a specific this context. Use bind when you want to create a new function with a specific this context to be invoked later.
JSON (JavaScript Object Notation) is a lightweight, text-based data format that uses JavaScript object syntax for structuring data. It was popularized by Douglas Crockford and is widely used for transmitting data between a server and a client in web applications. JSON files typically have a .json extension and use the MIME type application/json.
const obj = JSON.parse(jsonString);
const jsonString = '{"name":"John","age":30}'; const obj = JSON.parse(jsonString); // { name: "John", age: 30 }
const jsonString = JSON.stringify(object);
const obj = { name: "Jane", age: 25 }; const jsonString = JSON.stringify(obj); // '{"name":"Jane","age":25}'
The slice() method in JavaScript is used to extract a section of an array, returning a new array containing the selected elements. It does not modify the original array. The method takes two arguments:
You can also use negative indices, which count from the end of the array.
let arrayIntegers = [1, 2, 3, 4, 5]; let arrayIntegers1 = arrayIntegers.slice(0, 2); // [1, 2] let arrayIntegers2 = arrayIntegers.slice(2, 3); // [3] let arrayIntegers3 = arrayIntegers.slice(4); // [5] let arrayIntegers4 = arrayIntegers.slice(-3, -1); // [3, 4]
Note:
The slice() method does not mutate (change) the original array; instead, it returns a new array containing the extracted elements.
The splice() method in JavaScript is used to add, remove, or replace elements within an array. Unlike slice(), which creates a shallow copy and does not alter the original array, splice() modifies the original array in place and returns an array containing the removed elements.
array.splice(start, deleteCount, item1, item2, ...)
let arrayIntegersOriginal1 = [1, 2, 3, 4, 5]; let arrayIntegersOriginal2 = [1, 2, 3, 4, 5]; let arrayIntegersOriginal3 = [1, 2, 3, 4, 5]; // Remove the first two elements let arrayIntegers1 = arrayIntegersOriginal1.splice(0, 2); // arrayIntegers1: [1, 2] // arrayIntegersOriginal1 (after): [3, 4, 5] // Remove all elements from index 3 onwards let arrayIntegers2 = arrayIntegersOriginal2.splice(3); // arrayIntegers2: [4, 5] // arrayIntegersOriginal2 (after): [1, 2, 3] // Remove 1 element at index 3, then insert "a", "b", "c" at that position let arrayIntegers3 = arrayIntegersOriginal3.splice(3, 1, "a", "b", "c"); // arrayIntegers3: [4] // arrayIntegersOriginal3 (after): [1, 2, 3, "a", "b", "c", 5]
Note:
splice() method modifies the original array.Here are the key differences between slice() and splice() methods in JavaScript arrays:
slice() |
splice() |
|---|---|
| Does not modify the original array (immutable) | Modifies the original array (mutable) |
| Returns a shallow copy (subset) of selected elements | Returns an array of the removed elements |
| Used to extract elements from an array | Used to add, remove, or replace elements in an array |
Syntax: array.slice(start, end) |
Syntax: array.splice(start, deleteCount, ...items) |
Summary:
slice() when you want to copy or extract elements without altering the original array.splice() when you need to add, remove, or replace elements and want to change the original array.Objects and Maps both allow you to associate keys with values, retrieve those values, delete keys, and check if a key exists. Historically, Objects have been used as Maps, but there are several key differences that make Map a better choice in certain scenarios:
| Feature | Object | Map |
|---|---|---|
| Key Types | Only strings and symbols are valid keys | Any value can be used as a key (objects, functions, primitives) |
| Key Order | Keys are unordered (in practice, insertion order is mostly preserved for string keys, but not guaranteed) | Keys are ordered by insertion; iteration follows insertion order |
| Size Property | No built-in way to get the number of keys; must use Object.keys(obj).length |
Use the .size property for the number of entries |
| Iterability | Not directly iterable; must use Object.keys, Object.values, or Object.entries |
Directly iterable with for...of, .keys(), .values(), .entries() |
| Prototype | Has a prototype chain; may have default properties that can collide with custom keys (can be avoided with Object.create(null)) |
Does not have a prototype, so there are no default keys |
| Performance | May be less efficient for frequent additions/removals | Optimized for frequent additions and deletions |
| Serialization | Can be easily serialized to JSON | Cannot be directly serialized to JSON |
JavaScript provides two types of equality operators:
==, !=): Performs type conversion if the types differ, comparing values after converting them to a common type.===, !==): Compares both value and type, without any type conversion.===)NaN === NaN is false+0 === -0 is truetrue or both are false.null and undefined are not strictly equal.==)null == undefined is true."1" == 1 is true because the string is converted to a number.0 == false is true because false is converted to 0.0 == false // true (loose equality, type coercion) 0 === false // false (strict equality, different types) 1 == "1" // true (string converted to number) 1 === "1" // false (different types) null == undefined // true (special case) null === undefined // false (different types) '0' == false // true ('0' is converted to 0) '0' === false // false (different types) NaN == NaN // false (NaN is never equal to itself) NaN === NaN // false [] == [] // false (different array objects) [] === [] // false {} == {} // false (different object references) {} === {} // false
Arrow functions (also known as "lambda expressions") provide a concise syntax for writing function expressions in JavaScript. Introduced in ES6, arrow functions are often shorter and more readable, especially for simple operations or callbacks.
this, arguments, super, or new.target bindings. They inherit these from their surrounding (lexical) context.prototype property.new, yield, or as generator functions.const arrowFunc1 = (a, b) => a + b; // Multiple parameters, returns a + b const arrowFunc2 = a => a * 10; // Single parameter (parentheses optional), returns a * 10 const arrowFunc3 = () => {}; // No parameters, returns undefined const arrowFunc4 = (a, b) => { // Multiple statements require curly braces and explicit return const sum = a + b; return sum * 2; };
In JavaScript, first-class functions(first-class citizens) mean that functions are treated like any other variable. That means:
This capability enables powerful patterns like callbacks, higher-order functions, event handling, and functional programming in JavaScript.
For example, the handler function below is assigned to a variable and then passed as an argument to the addEventListener method.
const handler = () => console.log("This is a click handler function"); document.addEventListener("click", handler);
A first-order function is a function that doesnโt accept another function as an argument and doesnโt return a function as its return value. i.e, It's a regular function that works with primitive or non-function values.
const firstOrder = () => console.log("I am a first order function!");
A higher-order function is a function that either accepts another function as an argument, returns a function as its result, or both. This concept is a core part of JavaScript's functional programming capabilities and is widely used for creating modular, reusable, and expressive code.
The syntactic structure of higher order function will be explained with an example as follows,
// First-order function (does not accept or return another function) const firstOrderFunc = () => console.log("Hello, I am a first-order function"); // Higher-order function (accepts a function as an argument) const higherOrder = (callback) => callback(); // Passing the first-order function to the higher-order function higherOrder(firstOrderFunc);
In this example:
firstOrderFunc is a regular (first-order) function.
higherOrder is a higher-order function because it takes another function as an argument.
firstOrderFunc is also called a callback function because it is passed to and executed by another function.
A unary function (also known as a monadic function) is a function that accepts exactly one argument. The term "unary" simply refers to the function's arityโthe number of arguments it takes.
Let us take an example of unary function,
const unaryFunction = (a) => console.log(a + 10); // This will add 10 to the input and log the result unaryFunction(5); // Output: 15
In this example:
unaryFunction takes a single parameter a, making it a unary function.Currying is the process of transforming a function with multiple arguments into a sequence of nested functions, each accepting only one argument at a time.
This concept is named after mathematician Haskell Curry, and is commonly used in functional programming to enhance modularity and reuse.
const multiArgFunction = (a, b, c) => a + b + c; console.log(multiArgFunction(1, 2, 3)); // Output: 6
This is a standard function that takes three arguments at once.
const curryUnaryFunction = (a) => (b) => (c) => a + b + c; console.log(curryUnaryFunction(1)); // Returns: function (b) => ... console.log(curryUnaryFunction(1)(2)); // Returns: function (c) => ... console.log(curryUnaryFunction(1)(2)(3)); // Output: 6
Each function in the chain accepts one argument and returns the next function, until all arguments are provided and the final result is computed.
Improves code reusability โ You can partially apply functions with known arguments.
Enhances functional composition โ Easier to compose small, pure functions.
Encourages clean, modular code โ You can split logic into smaller single-responsibility functions.
A pure function is a function whose output depends only on its input arguments and produces no side effects. This means that given the same inputs, a pure function will always return the same output, and it does not modify any external state or data.
Let's take an example to see the difference between pure and impure functions,
// Impure Function let numberArray = []; const impureAddNumber = (number) => numberArray.push(number); // Pure Function const pureAddNumber = (number) => (inputArray) => inputArray.concat([number]); // Usage console.log(impureAddNumber(6)); // returns 1 console.log(numberArray); // returns [6] console.log(pureAddNumber(7)(numberArray)); // returns [6, 7] console.log(numberArray); // remains [6]
impureAddNumber changes the external variable numberArray and returns the new length of the array, making it impure.pureAddNumber creates a new array with the added number and does not modify the original array, making it pure.Some of the major benefits of pure functions are listed below,
The let keyword in JavaScript is used to declare a block-scoped local variable. This means that variables declared with let are only accessible within the block, statement, or expression where they are defined. This is a significant improvement over the older var keyword, which is function-scoped (or globally-scoped if declared outside a function), and does not respect block-level scoping.
let:{} pair).let declarations are hoisted, they are not initialized until the code defining them is executed. Accessing them before declaration results in a ReferenceError (temporal dead zone).let.let counter = 30; if (counter === 30) { let counter = 31; console.log(counter); // Output: 31 (block-scoped variable inside if-block) } console.log(counter); // Output: 30 (outer variable, unaffected by inner block)
In this example, the counter inside the if block is a separate variable from the one outside. The let keyword ensures that both have their own distinct scope.
In summary, you need to use let when you want variables to be limited to the block in which they are defined, preventing accidental overwrites and bugs related to variable scope.
You can list out the differences in a tabular format
| var | let |
|---|---|
| It has been available from the beginning of JavaScript | Introduced as part of ES6 |
| It has function scope | It has block scope |
| Variable declaration will be hoisted, initialized as undefined | Hoisted but not initialized |
| It is possible to re-declare the variable in the same scope | It is not possible to re-declare the variable |
Let's take an example to see the difference,
function userDetails(username) { if (username) { console.log(salary); // undefined due to hoisting console.log(age); // ReferenceError: Cannot access 'age' before initialization let age = 30; var salary = 10000; } console.log(salary); //10000 (accessible due to function scope) console.log(age); //error: age is not defined(due to block scope) } userDetails("John");
The keyword let was chosen because it originates from mathematical notation, where "let" is used to introduce new variables (for example, "let x = 5"). This term was adopted by several early programming languages such as Scheme and BASIC, establishing a tradition in computer science. JavaScript follows this convention by using let to declare variables with block scope, providing a modern alternative to var. The choice helps make the language more familiar to programmers coming from other languages and aligns with the mathematical practice of variable assignment.
When you try to redeclare variables using let or const in multiple case clauses of a switch statement, you will get a SyntaxError. This happens because, in JavaScript, all case clauses within a switch statement share the same block scope. For example:
let counter = 1; switch (x) { case 0: let name; break; case 1: let name; // SyntaxError: Identifier 'name' has already been declared break; }
To avoid this error, you can create a new block scope within each case clause by wrapping the code in curly braces {}. This way, each let or const declaration is scoped only to that block, and redeclaration errors are avoided:
let counter = 1; switch (x) { case 0: { let name; // code for case 0 break; } case 1: { let name; // No SyntaxError // code for case 1 break; } }
That means, to safely redeclare variables in different cases of a switch statement, wrap each caseโs code in its own block using curly braces. This ensures each variable declaration is scoped to its specific case block.
The Temporal Dead Zone (TDZ) refers to the period between the start of a block and the point where a variable declared with let or const is initialized. During this time, the variable exists in scope but cannot be accessed, and attempting to do so results in a ReferenceError.
This behavior is part of JavaScript's ES6 (ECMAScript 2015) specification and applies only to variables declared with let and const, not var. Variables declared with var are hoisted and initialized with undefined, so accessing them before the declaration does not throw an error, though it can lead to unexpected results.
function someMethod() { console.log(counter1); // Output: undefined (due to var hoisting) console.log(counter2); // Throws ReferenceError (TDZ for let) var counter1 = 1; let counter2 = 2; }
IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. The signature of it would be as below,
(function () { // logic here })();
The primary reason to use an IIFE is to obtain data privacy because any variables declared within the IIFE cannot be accessed by the outside world. i.e, If you try to access variables from the IIFE then it throws an error as below,
(function () { var message = "IIFE"; console.log(message); })(); console.log(message); //Error: message is not defined
encodeURI() function is used to encode an URL. This function requires a URL string as a parameter and return that encoded string.
decodeURI() function is used to decode an URL. This function requires an encoded URL string as parameter and return that decoded string.
Note: If you want to encode characters such as / ? : @ & = + $ # then you need to use encodeURIComponent().
let uri = "employeeDetails?name=john&occupation=manager"; let encoded_uri = encodeURI(uri); let decoded_uri = decodeURI(encoded_uri);
Memoization is a functional programming technique which attempts to increase a functionโs performance by caching its previously computed results. Each time a memoized function is called, its parameters are used to index the cache. If the data is present, then it can be returned, without executing the entire function. Otherwise the function is executed and then the result is added to the cache. Let's take an example of adding function with memoization,
const memoizeAddition = () => { let cache = {}; return (value) => { if (value in cache) { console.log("Fetching from cache"); return cache[value]; // Here, cache.value cannot be used as property name starts with the number which is not a valid JavaScript identifier. Hence, can only be accessed using the square bracket notation. } else { console.log("Calculating result"); let result = value + 20; cache[value] = result; return result; } }; }; // returned function from memoizeAddition const addition = memoizeAddition(); console.log(addition(20)); //output: 40 calculated console.log(addition(20)); //output: 40 cached
Hoisting is a JavaScript mechanism where variables, function declarations and classes are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialisation. Let's take a simple example of variable hoisting,
console.log(message); //output : undefined var message = "The variable Has been hoisted";
The above code looks like as below to the interpreter,
var message; console.log(message); message = "The variable Has been hoisted";
In the same fashion, function declarations are hoisted too
message("Good morning"); //Good morning function message(name) { console.log(name); }
This hoisting makes functions to be safely used in code before they are declared.
In ES6, Javascript classes are primarily syntactic sugar over JavaScriptโs existing prototype-based inheritance. For example, the prototype based inheritance written in function expression as below,
function Bike(model, color) { this.model = model; this.color = color; } Bike.prototype.getDetails = function () { return this.model + " bike has" + this.color + " color"; };
Whereas ES6 classes can be defined as an alternative
class Bike { constructor(color, model) { this.color = color; this.model = model; } getDetails()
codeaashu/javascript-interview-questions is a public repo on GitHub by codeaashu. Master JavaScript Interviews with This Curated List of 1000 Questions that Help You Prepare for Any Frontend or Full-Stack Role ๐.
It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-08-29. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Use claude-code for free in the terminal, VSCode extension or via discord like openclaw


Helpmate is a AI Chat Bot web app where you can ask any question and you will get the answer
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/codeaashu/javascript-interview-questionsTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.
