Tech

JavaScript

JavaScript is the language of the web — the only programming language that runs natively in every browser. It has evolved dramatically with ES6+ features and now powers full-stack development through Node.js. Interviews typically probe your understanding of the event loop, closures, prototypal inheritance, asynchronous patterns (Promises, async/await), and how the browser renders and executes code.

What you get

Questions

20

Difficulty

3 levels

Answer Formats

2

Use the toggle on each card to move between an interview-ready answer and a simpler explanation. Questions are sorted from beginner to advanced, and the keywords are highlighted. You can also blur the answers to practice recalling them from memory.

Questions

Practice the answers out loud.

All topics

Question 1

What is JavaScript and where is it used?

Beginner

How to answer in an interview

JavaScript is a dynamically-typed, interpreted scripting language originally designed to make web pages interactive, running natively in every browser. With the introduction of Node.js, it can also run server-side, enabling full-stack development, and it's widely used for web apps, mobile apps, and even desktop applications.

Question 2

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

Beginner

How to answer in an interview

'var' is function-scoped and hoisted with an initial value of undefined, which can lead to bugs. 'let' is block-scoped and allows reassignment, while 'const' is also block-scoped but prevents reassignment after initialization. Modern JavaScript favors 'let' and 'const' over 'var' for more predictable scoping.

Question 3

What is the difference between == and === in JavaScript?

Beginner

How to answer in an interview

'==' performs type coercion before comparing values, so different types can be considered equal, e.g. '1 == "1"' is true. '===' checks both value and type without coercion, making it stricter and generally the recommended choice to avoid unexpected bugs.

Question 4

What is the difference between null and undefined?

Beginner

How to answer in an interview

'undefined' means a variable has been declared but not yet assigned a value, and it's the default value JavaScript assigns automatically. 'null' is an intentional assignment representing 'no value' or emptiness, explicitly set by the developer.

Question 5

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

Beginner

How to answer in an interview

Arrow functions provide a shorter syntax for writing functions and do not bind their own 'this', 'arguments', or 'super', instead inheriting these from the surrounding scope. This makes them especially useful in callbacks where preserving the outer 'this' context matters, but they aren't suitable as object methods that need dynamic 'this' binding.

Question 6

What is the difference between synchronous and asynchronous code?

Beginner

How to answer in an interview

Synchronous code executes sequentially, blocking further execution until the current operation finishes. Asynchronous code allows the program to continue running other tasks while waiting for an operation like a network request to complete, using mechanisms like callbacks, Promises, or async/await.

Question 7

What is a callback function?

Beginner

How to answer in an interview

A callback function is a function passed as an argument to another function, to be executed after some operation completes. Callbacks are foundational to JavaScript's asynchronous model, though excessive nesting can lead to 'callback hell', which Promises and async/await help resolve.

Question 8

Explain scope in JavaScript (global, function, block).

Beginner

How to answer in an interview

Scope determines the accessibility of variables. Global scope variables are accessible anywhere in the code, function scope variables declared with 'var' are accessible only within that function, and block scope variables declared with 'let' or 'const' are limited to the enclosing curly braces, such as an if block or loop.

Question 9

What is JSON and how do you parse or stringify it in JavaScript?

Beginner

How to answer in an interview

JSON, or JavaScript Object Notation, is a lightweight text-based data interchange format. JSON.parse() converts a JSON string into a JavaScript object, while JSON.stringify() converts a JavaScript object into a JSON string, commonly used when sending or receiving data from APIs.

Question 10

What is hoisting in JavaScript?

Intermediate

How to answer in an interview

Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their scope during compilation, before code execution. Function declarations are fully hoisted, but 'let' and 'const' variables are hoisted into a 'temporal dead zone' where they exist but cannot be accessed until their declaration line runs.

Question 11

Explain closures in JavaScript.

Intermediate

How to answer in an interview

A closure is a function that retains access to variables from its enclosing lexical scope even after that outer function has finished executing. Closures are commonly used to create private variables, implement data encapsulation, and build factory functions or memoization patterns.

Question 12

What are Promises in JavaScript?

Intermediate

How to answer in an interview

A Promise represents the eventual result of an asynchronous operation and can be in one of three states: pending, fulfilled, or rejected. You attach handlers using .then() for success and .catch() for errors, allowing cleaner asynchronous code than deeply nested callbacks.

Question 13

Explain async/await in JavaScript.

Intermediate

How to answer in an interview

async/await is syntactic sugar built on top of Promises that lets asynchronous code be written in a more synchronous, readable style. Marking a function 'async' means it always returns a Promise, and 'await' pauses execution within that function until the awaited Promise resolves, without blocking the main thread.

Question 14

How does the 'this' keyword behave in JavaScript?

Intermediate

How to answer in an interview

'this' refers to the object that is currently executing the function, and its value depends on how the function is called rather than where it's defined. In a regular function, 'this' can change based on the caller, while arrow functions don't have their own 'this' and instead inherit it from the enclosing lexical scope. Methods like call(), apply(), and bind() let you explicitly set 'this'.

Question 15

Explain event bubbling and capturing.

Intermediate

How to answer in an interview

Event bubbling means an event triggered on a nested element propagates upward through its ancestors in the DOM, while event capturing propagates downward from the root to the target element first. By default, most event listeners use the bubbling phase, but you can opt into capturing by passing a third argument to addEventListener.

Question 16

What is debouncing and throttling?

Intermediate

How to answer in an interview

Debouncing delays a function's execution until a certain period of inactivity has passed, so rapid repeated triggers only fire the function once at the end. Throttling ensures a function runs at most once within a specified time interval, regardless of how many times the event fires. Both are used to optimize performance for frequent events like scrolling or typing.

Question 17

What are higher-order functions in JavaScript?

Intermediate

How to answer in an interview

A higher-order function is a function that takes another function as an argument, returns a function, or both. Common examples in JavaScript include map(), filter(), and reduce(), which allow declarative and reusable data transformations rather than manual loops.

Question 18

Explain the JavaScript event loop.

Advanced

How to answer in an interview

JavaScript runs on a single thread with a call stack that executes synchronous code. Asynchronous operations like timers or network requests are handled by the browser or Node APIs, and their callbacks are pushed to a task queue or microtask queue. The event loop continuously checks if the call stack is empty and then pushes queued callbacks onto it, with microtasks like Promises resolved before macrotasks like setTimeout.

Question 19

Explain prototypal inheritance in JavaScript.

Advanced

How to answer in an interview

JavaScript objects can inherit properties and methods from other objects via a prototype chain, rather than classical class-based inheritance. When a property isn't found on an object, JavaScript looks up the chain through its prototype until it finds the property or reaches null. ES6 classes are essentially syntactic sugar over this prototype-based system.

Question 20

Explain memory leaks in JavaScript and how to avoid them.

Advanced

How to answer in an interview

A memory leak occurs when memory that's no longer needed isn't released, often because references are unintentionally kept alive, such as forgotten event listeners, uncleared timers, or closures holding onto large objects. To avoid leaks, developers should remove event listeners when no longer needed, clear intervals/timeouts, and avoid unnecessary global variable references.

More in Tech

Keep browsing related topics.

Browse all