DEV Community

Tarun Dudhatra
Tarun Dudhatra

Posted on Originally published at databeautifier.com

Top JavaScript Interview Questions and Answers (2026)

JavaScript remains one of the most in-demand skills for developers. Whether you're preparing for your first frontend role or leveling up to a senior position, these questions will help you get ready.

📌 For the full list with detailed answers, visit: JavaScript Interview Questions – DataBeautifier


1. What is the difference between var, let, and const?

  • var is function-scoped and hoisted. It can be re-declared and updated.
  • let is block-scoped. It can be updated but not re-declared in the same scope.
  • const is block-scoped. It cannot be updated or re-declared — but objects/arrays it points to can still be mutated.
var x = 1;   // function-scoped
let y = 2;   // block-scoped
const z = 3; // block-scoped, read-only binding
Enter fullscreen mode Exit fullscreen mode

2. What is a closure in JavaScript?

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

function counter() {
  let count = 0;
  return function () {
    count++;
    return count;
  };
}

const increment = counter();
console.log(increment()); // 1
console.log(increment()); // 2
Enter fullscreen mode Exit fullscreen mode

Closures are widely used for data encapsulation, currying, and factory functions.


3. What is the difference between == and ===?

  • == performs type coercion — converts both values to the same type before comparing.
  • === performs strict equality — no type conversion, both value and type must match.
0 == '0'  // true  (type coercion)
0 === '0' // false (strict)
Enter fullscreen mode Exit fullscreen mode

Always prefer === to avoid unexpected bugs.


4. What is event delegation?

Event delegation is a technique where you attach a single event listener to a parent element instead of multiple listeners on each child. It leverages event bubbling.

document.getElementById('list').addEventListener('click', function (e) {
  if (e.target.tagName === 'LI') {
    console.log('Clicked:', e.target.textContent);
  }
});
Enter fullscreen mode Exit fullscreen mode

This improves performance, especially for dynamic lists.


5. What is the difference between null and undefined?

  • undefined means a variable has been declared but not assigned a value.
  • null is an intentional absence of value, explicitly set by the developer.
let a;          // undefined
let b = null;   // null
Enter fullscreen mode Exit fullscreen mode

typeof null === 'object' is a known JavaScript quirk — a historical bug in the spec.


6. How does this work in JavaScript?

The value of this depends on how a function is called:

Context this refers to
Global scope window (browser) or global (Node.js)
Inside a method The object the method belongs to
Arrow function Inherits this from surrounding lexical scope
new keyword The newly created object
const obj = {
  name: 'DataBeautifier',
  greet() { console.log(this.name); }
};
obj.greet(); // 'DataBeautifier'
Enter fullscreen mode Exit fullscreen mode

7. What is a Promise?

A Promise represents a value that may be available now, in the future, or never. It has three states: pending, fulfilled, and rejected.

const fetchData = new Promise((resolve, reject) => {
  setTimeout(() => resolve('Data loaded'), 1000);
});

fetchData.then(data => console.log(data)).catch(err => console.error(err));
Enter fullscreen mode Exit fullscreen mode

8. What is the difference between call, apply, and bind?

All three explicitly set this:

  • call(thisArg, arg1, arg2) — invokes immediately, args passed individually
  • apply(thisArg, [args]) — invokes immediately, args passed as array
  • bind(thisArg) — returns a new function with this permanently bound
function greet(greeting) { console.log(`${greeting}, ${this.name}`); }
const user = { name: 'Tarun' };

greet.call(user, 'Hello');     // Hello, Tarun
greet.apply(user, ['Hi']);     // Hi, Tarun
greet.bind(user)('Hey');       // Hey, Tarun
Enter fullscreen mode Exit fullscreen mode

9. What are arrow functions and how do they differ from regular functions?

Arrow functions are a shorter syntax and do not have their own this, arguments, or prototype.

// Regular function
const add = function(a, b) { return a + b; };

// Arrow function
const add = (a, b) => a + b;
Enter fullscreen mode Exit fullscreen mode

Arrow functions are ideal for callbacks. Avoid them as object methods since they don't bind this.


10. What is event bubbling vs event capturing?

  • Bubbling: Events propagate from the target element up to the root (default).
  • Capturing: Events propagate from the root down to the target.

Pass true as the third argument to addEventListener to use capturing mode.


Want the Full List?

This covers the basics. We've compiled a complete set of beginner, intermediate, and advanced JavaScript interview questions at:

👉 JavaScript Interview Questions & Answers – DataBeautifier

Topics covered: Prototypes, async/await, ES6+ features, design patterns, performance optimization, and more. Bookmark it before your next interview! 🚀

Top comments (0)