Home Resources Questionnaires JavaScript
🧠 JS Interview Questions 🌐 JavaScript ✅ Free 🔥 Most Popular

Top 60+ JavaScript Interview
Questions For Beginners

This Top 60+ JavaScript Questions list is perfect for interview preparation, coding practice, and strengthening your core concepts. By mastering these questions, you can confidently tackle JavaScript interviews and build powerful applications.

60+ Questions
~Daily 10 min read
3.2k+ downloads
4.9 / 5.0
Your Progress 0 / 60 answered
Start Reading →
🌐
60+ Questions
50+ Topics
3.2k Downloads
4.9★ Rating
Covers
Variables Data Types Functions Scope Closures Hoisting Promises Async/Await DOM Events
K2
K2 Infocom Team
Industry Experts
60 Total Questions
19 Easy
31 Medium
10 Hard
~Daily 10 min Read Time
🟢
JavaScript Basics
Variables, Data Types, Operators, Loops
10 Questions
01
What is JavaScript?
Easy

JavaScript is a high-level, interpreted programming language that is primarily used to make web pages interactive and dynamic. It allows developers to create functionalities like button clicks, form validation, animations, DOM manipulation, and API calls. JavaScript can run on both the client-side (browser) and server-side (Node.js), making it a versatile language for full-stack development.

Key Points:
- Runs in the browser without installation.
- Supports object-oriented, functional, and event-driven programming.
- Enables dynamic content updates without reloading the page.
- Works with HTML and CSS to create modern web applications.

02
What are data types in JavaScript?
Easy

JavaScript provides two types of data types:
1. Primitive (Value Type): These store actual values and are stored in stack memory. Each variable gets its own separate memory. (Examples: string, number, boolean, null, undefined, bigint)
2. Non-Primitive (Reference Type): These store reference (address) in stack but actual data is stored in heap memory. Multiple variables can point to the same data. (Examples: object, array, function)

03
What is the difference between var, let, and const?
Easy

var: var is function-scoped and can be re-assigned and redeclared. It is the older way to declare variables.
let: let is block-scoped and can be re-assigned, but cannot be redeclared in the same scope. It is the modern way to declare variables.
const: const is block-scoped and cannot be re-assigned or redeclared. It is used for constant values.

04
What is the difference between == and === in JavaScript?
Easy
In JavaScript, == is called the equality operator. It checks if the values are the same, even if the data types are different. === is called the strict equality operator. It checks if both the value and type are the same.

Example:
5 == "5" → true (value is same, type is converted)
5 === "5" → false (value is same, but type is different)

05
What is hoisting in JavaScript?
Medium

Hoisting means JavaScript moves variable and function declarations to the top of their scope before running the code. This allows you to use functions and variables even before they are declared.

Example:
console.log(a); // undefined
var a = 5; // The declaration 'var a' is hoisted, but value is assigned later

06
What is a function in JavaScript?
Easy

A function is a block of code used to perform a specific task.

Example:

 function greet() { console.log("Hello"); } 

07
What is an array in JavaScript?
Easy

An array stores multiple values in a single variable.

Example:

 let arr = [1, 2, 3]; 

08
What is an object in JavaScript?
Easy

An object stores data in key-value pairs.

Example:

 let user = { name: "Pranav", age: 20 }; 

09
What is the difference between undefined and null?
Easy

In JavaScript: undefined means a variable has been declared but no value is assigned to it.
null means the variable is intentionally set to have no value.

Example:
let x;
console.log(x); // undefined

let y = null;
console.log(y); // null

10
What are arrow functions in JavaScript?
Easy

Arrow functions are a short way to write functions.

Example:

  const add = (a, b) => a + b;  

⚙️
Functions & Scope
Closures, Hoisting, Scope, IIFE
10 Questions
01
What is function scope?
Easy

Function scope means variables declared inside a function are only accessible within that function. They cannot be accessed outside the function.

Example:

                                    
function test() {
    let x = 10;
    console.log(x); // 10
}
console.log(x); // Error: x is not defined
                    

02
What is block scope?
Easy

Block scope means variables declared inside a block (like inside { }) using let or const are only accessible inside that block.

Example:


if(true) {
    let y = 20;
    console.log(y); // 20
}
console.log(y); // Error: y is not defined
                    

03
What is global scope?
Easy

Global scope means variables declared outside any function or block are accessible from anywhere in the code.

Example:


let z = 30; // global variable
function show() {
    console.log(z); // 30
}
console.log(z); // 30
                    

04
Difference between function declaration & function expression
Medium

Function Declaration: Defined with function keyword, hoisted to the top of scope.
Function Expression: Function assigned to a variable, not hoisted.

Example:


// Declaration
function greet() { console.log("Hi"); }
greet(); // Hi

// Expression
const greet2 = function() { console.log("Hello"); };
greet2(); // Hello
                    

05
What is a closure?
Medium

A closure is a function that remembers variables from its outer scope even after the outer function has finished executing.

Example:


function outer() {
    let count = 0;
    return function inner() {
        count++;
        return count;
    };
}
const counter = outer();
console.log(counter()); // 1
console.log(counter()); // 2
                    

06
What is lexical scope?
Medium

Lexical scope means inner functions can access variables from their outer functions, based on where the function is written in the code.

Example:


function outer() {
    let name = "Pranav";
    function inner() {
        console.log(name); // Pranav
    }
    inner();
}
outer();
                    

07
What is an IIFE?
Medium

IIFE (Immediately Invoked Function Expression) is a function that runs immediately after it is defined.

Example:


(function() {
    console.log("Runs immediately!");
})();
                    

08
What is a callback function?
Medium

A callback function is a function passed as an argument to another function and executed later.

Example:


function greet(name, callback) {
    console.log("Hello " + name);
    callback();
}
greet("Pranav", function() { console.log("Callback executed!"); });
                    

09
Difference between call, apply, and bind?
Hard

- call: Calls a function with a given `this` and arguments separately.
- apply: Calls a function with a given `this` and arguments as an array.
- bind: Returns a new function with bound `this`.

Example:


function greet(city) { console.log(this.name + " from " + city); }
let user = { name: "Pranav" };
greet.call(user, "Surat"); // Pranav from Surat
greet.apply(user, ["Surat"]); // Pranav from Surat
let greetUser = greet.bind(user);
greetUser("Surat"); // Pranav from Surat
                    

10
What is recursion in functions?
Hard

Recursion is when a function calls itself to solve a problem, usually with a base condition to stop.

Example:


function factorial(n) {
    if(n === 0) return 1;
    return n * factorial(n-1);
}
console.log(factorial(5)); // 120
                    

🧠
Objects & Arrays
this, prototype, map, filter, reduce
10 Questions
01
What is an object in JavaScript?
Easy

An object is a collection of key-value pairs that stores related data and functionality. Keys are strings (or symbols) and values can be any data type, including other objects or functions.

Example:


let user = {
    name: "Pranav",
    age: 20,
    greet: function() {
        console.log("Hello " + this.name);
    }
};
console.log(user.name); // Pranav
user.greet(); // Hello Pranav
                    

02
What is an array in JavaScript?
Easy

An array is an ordered list of values stored in a single variable. Arrays can hold different data types, including numbers, strings, objects, or even other arrays.

Example:


let fruits = ["Apple", "Banana", "Mango"];
console.log(fruits[0]); // Apple
                    

03
How to loop through an array?
Medium

You can loop through an array using for, for...of, forEach loops.

Example:


let numbers = [1, 2, 3, 4];

// Using for loop
for(let i = 0; i < numbers.length; i++) {
    console.log(numbers[i]);
}

// Using for...of
for(let num of numbers) {
    console.log(num);
}

// Using forEach
numbers.forEach(num => console.log(num));
                    

04
How to loop through an object?
Medium

You can loop through an object using for...in loop.

Example:


let user = { name: "Pranav", age: 20 };

for(let key in user) {
    console.log(key + ": " + user[key]);
}
// Output:
// name: Pranav
// age: 20
                    

05
What are object methods?
Medium

Object methods are functions that are stored as object properties and can perform actions using the object data.

Example:


let user = {
    name: "Pranav",
    greet: function() {
        console.log("Hello " + this.name);
    }
};
user.greet(); // Hello Pranav
                    

06
Difference between shallow and deep copy of objects
Hard

Shallow copy: Copies only the first level, nested objects are shared.
Deep copy: Copies all levels, including nested objects, creating a new independent object.

Example:


let obj = { a: 1, b: { c: 2 } };
let shallow = { ...obj }; // nested b is shared
let deep = JSON.parse(JSON.stringify(obj)); // full deep copy
                    

07
What is the spread operator?
Medium

The spread operator (...) allows you to expand arrays or objects into individual elements or key-value pairs.

Example:


let arr1 = [1, 2];
let arr2 = [...arr1, 3, 4]; // [1, 2, 3, 4]

let obj1 = { a: 1 };
let obj2 = { ...obj1, b: 2 }; // { a: 1, b: 2 }
                    

08
What is array destructuring?
Medium

Array destructuring allows extracting values from arrays into individual variables easily.

Example:


let arr = [1, 2, 3];
let [a, b, c] = arr;
console.log(a, b, c); // 1 2 3
                    

09
What is object destructuring?
Medium

Object destructuring allows extracting values from objects into variables based on keys.

Example:


let user = { name: "Pranav", age: 20 };
let { name, age } = user;
console.log(name, age); // Pranav 20
                    

10
How to merge objects and arrays?
Medium

You can merge objects using spread operator and arrays using concat or spread operator.

Example:


// Merge arrays
let arr1 = [1, 2];
let arr2 = [3, 4];
let mergedArr = [...arr1, ...arr2]; // [1,2,3,4]

// Merge objects
let obj1 = { a: 1 };
let obj2 = { b: 2 };
let mergedObj = { ...obj1, ...obj2 }; // { a:1, b:2 }
                    

Async JavaScript
Promises, Async/Await, Event Loop
10 Questions
01
What is asynchronous JavaScript?
Medium

Asynchronous JavaScript allows code to run without blocking the execution of other code. It is useful for tasks like API calls, timers, and reading files.

Example:


console.log("Start");
setTimeout(() => console.log("Async Task"), 1000);
console.log("End");
// Output:
// Start
// End
// Async Task (after 1 second)
                    

02
What is the event loop in JavaScript?
Medium

The event loop is a mechanism that allows JavaScript to handle asynchronous operations while maintaining a single-threaded execution.

Example:


console.log("Start");
setTimeout(() => console.log("Timer"), 0);
console.log("End");
// Output:
// Start
// End
// Timer
                    

03
What is a Promise in JavaScript?
Medium

A Promise is an object representing the eventual completion or failure of an asynchronous operation.

Example:


let promise = new Promise((resolve, reject) => {
    let success = true;
    if(success) resolve("Done");
    else reject("Error");
});
promise.then(msg => console.log(msg)).catch(err => console.log(err));
                    

04
Difference between synchronous & asynchronous code
Medium

Synchronous code: Runs line by line, blocking next statements until complete.
Asynchronous code: Runs without blocking, allowing other code to execute while waiting for results.

Example:


// Synchronous
console.log("Start");
console.log("End");

// Asynchronous
console.log("Start");
setTimeout(() => console.log("Async"), 1000);
console.log("End");
                    

05
How to handle Promises using .then()?
Medium

.then() is used to handle the resolved value of a Promise.

Example:


fetch("https://api.example.com/data")
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.log(error));
                    

06
What is async/await?
Medium

async/await is a syntax that makes asynchronous code look like synchronous code for better readability.

Example:


async function fetchData() {
    try {
        let response = await fetch("https://api.example.com/data");
        let data = await response.json();
        console.log(data);
    } catch(error) {
        console.log(error);
    }
}
fetchData();
                    

07
Difference between Promise.all and Promise.race
Hard

Promise.all: Waits for all promises to resolve or reject.
Promise.race: Resolves or rejects as soon as one promise settles.

08
What is the fetch API?
Medium

The fetch API allows making network requests and handling responses as promises.

Example:


fetch("https://api.example.com/data")
  .then(response => response.json())
  .then(data => console.log(data));
                    

09
How to handle errors in async code?
Medium

Errors can be handled using .catch() for promises or try/catch with async/await.

10
What are generators in JavaScript?
Hard

Generators are functions that can pause and resume execution using yield.

Example:


function* gen() {
    yield 1;
    yield 2;
}
let g = gen();
console.log(g.next().value); // 1
console.log(g.next().value); // 2
                    

🌐
DOM & Events
DOM Manipulation, Event Handling
10 Questions
01
What is the DOM in JavaScript?
Easy

The DOM (Document Object Model) is a programming interface that represents the HTML structure of a web page as a tree of objects. JavaScript can interact with the DOM to read, modify, or delete HTML elements and content.

Example:


let heading = document.getElementById("title");
console.log(heading.innerText);
                    

02
How to select elements in the DOM?
Easy

JavaScript provides multiple methods to select elements: getElementById, getElementsByClassName, getElementsByTagName, querySelector, querySelectorAll.

Example:


// By ID
let title = document.getElementById("title");

// By class
let items = document.getElementsByClassName("item");

// Using querySelector
let firstItem = document.querySelector(".item");
                    

03
How to change content of elements?
Easy

You can change content using innerText, innerHTML, or textContent properties.

Example:


let heading = document.getElementById("title");
heading.innerText = "New Title";
heading.innerHTML = "Updated Title";
                    

04
How to create elements dynamically?
Medium

You can create elements using document.createElement and append them to the DOM using appendChild or append.

Example:


let div = document.createElement("div");
div.innerText = "Hello World!";
document.body.appendChild(div);
                    

05
What are event listeners?
Easy

Event listeners are functions that wait for specific events (like click, mouseover, input) on elements and execute code when those events occur.

Example:


let btn = document.getElementById("btn");
btn.addEventListener("click", function() {
    alert("Button clicked!");
});
                    

06
Difference between inline and addEventListener?
Medium

Inline events are added directly in HTML attributes (onclick, onmouseover), while addEventListener attaches events via JavaScript, allowing multiple listeners for the same element and better separation of HTML and JS.

Example:


// Inline (HTML)
// 

// addEventListener (JS)
btn.addEventListener("click", () => alert("Clicked"));
                    

07
What is event bubbling and capturing?
Hard

Event bubbling: Events propagate from the innermost element to the outer elements.
Event capturing: Events propagate from the outer element to the inner element.

Example:


parentDiv.addEventListener("click", () => console.log("Parent"), true); // capturing
childDiv.addEventListener("click", () => console.log("Child")); // bubbling
                    

08
What is event delegation?
Medium

Event delegation is a technique where you attach a single event listener to a parent element to handle events on its child elements dynamically.

Example:


document.getElementById("list").addEventListener("click", function(e) {
    if(e.target && e.target.nodeName == "LI") {
        console.log("List item clicked: " + e.target.innerText);
    }
});
                    

09
How to prevent default behavior of events?
Medium

Use event.preventDefault() inside the event handler to prevent the default action of an element (like link navigation or form submission).

Example:


let link = document.querySelector("a");
link.addEventListener("click", function(e) {
    e.preventDefault();
    console.log("Default navigation prevented");
});
                    

10
How to stop event propagation?
Medium

Use event.stopPropagation() inside the event handler to stop the event from bubbling or capturing further.

Example:


childDiv.addEventListener("click", function(e) {
    e.stopPropagation();
    console.log("Event stopped at child");
});
                    

🚀
Advanced JS
Prototype, Prototypal Inheritance, this keyword, ES6 Modules, Symbol, WeakMap / WeakSet, Getters & Setters, Generators, Call Stack & Task Queue, Memory Management
10 Questions
01
What is prototype in JavaScript?
Medium

In JavaScript, every object has a prototype property which is a reference to another object. Prototypes are used to implement inheritance and share methods across objects without duplicating code.

Example:


function Person(name) {
    this.name = name;
}
Person.prototype.greet = function() {
    console.log("Hello " + this.name);
};
let p1 = new Person("Pranav");
p1.greet(); // Hello Pranav
                    

02
What is prototypal inheritance?
Medium

Prototypal inheritance allows objects to inherit properties and methods from other objects via the prototype chain.

Example:


let animal = { eats: true };
let rabbit = Object.create(animal);
console.log(rabbit.eats); // true (inherited from animal)
                    

03
What is the this keyword in JavaScript?
Easy

this refers to the context object in which a function is executed. Its value depends on how the function is called.

Example:


const obj = { name: "Pranav", greet() { console.log(this.name); } };
obj.greet(); // Pranav
function test() { console.log(this); }
test(); // window (in browser)
                    

04
What are ES6 modules?
Medium

ES6 modules allow you to export and import code (functions, objects, variables) between different JavaScript files, improving code organization and reusability.

Example:


// utils.js
export function add(a, b) { return a + b; }

// main.js
import { add } from './utils.js';
console.log(add(2, 3)); // 5
                    

05
What is a Symbol in JavaScript?
Hard

Symbol is a unique and immutable primitive value used as an identifier for object properties, preventing property name conflicts.

Example:


let id = Symbol("id");
let user = { [id]: 123 };
console.log(user[id]); // 123
                    

06
What are WeakMap and WeakSet?
Hard

WeakMap and WeakSet are special collections that hold weak references to objects, meaning they do not prevent garbage collection.

Example:


let wm = new WeakMap();
let obj = {};
wm.set(obj, "data");
obj = null; // object can be garbage collected
                    

07
What are getters and setters?
Medium

Getters and setters allow you to define methods to get or set object property values while controlling access and adding custom behavior.

Example:


let user = {
    firstName: "Pranav",
    lastName: "Chavda",
    get fullName() { return this.firstName + " " + this.lastName; },
    set fullName(name) { [this.firstName, this.lastName] = name.split(" "); }
};
console.log(user.fullName); // Pranav Chavda
user.fullName = "John Doe";
console.log(user.firstName); // John
                    

08
What are generators in JavaScript?
Hard

Generators are special functions that can pause execution and resume later using the yield keyword.

Example:


function* gen() {
    yield 1;
    yield 2;
    yield 3;
}
let g = gen();
console.log(g.next().value); // 1
console.log(g.next().value); // 2
                    

09
What is the difference between call stack and task queue?
Hard

The call stack keeps track of function execution in order, while the task queue stores asynchronous callbacks waiting to be executed after the call stack is empty.

Example: Functions inside setTimeout go to the task queue, not the call stack immediately.

10
What is memory management and garbage collection in JS?
Medium

JavaScript automatically manages memory by allocating space for objects and variables, and removing them when they are no longer needed. This process is called garbage collection.

Example: Objects no longer referenced are automatically removed from memory by the JS engine.

📥

Get All 60 Questions

Download the complete PDF with all 60 Q&A, code examples, and interview tips. Perfectly formatted for offline study.

No sign-up required · Instant download · 2.1 MB

Keep Practising

More questionnaires to sharpen your skills

📥

Get Notified of New Resources

We drop new questionnaires, question sets and career guides every week.
Subscribe to get them first — completely free.

No spam. Unsubscribe anytime.

Join WhatsApp Channel