Interview Q&A / JavaScript
JavaScript interview questions
Closures, the event loop, this, promises and the core language questions every frontend round asks.
Prefer rapid revision? Practise JavaScript short interview answers →
- What is a closure in JavaScript?
A closure is a function that remembers the variables from the place where it was created, even after that outer function has finished running.
BeginnerIn-depth2 min read - Is JavaScript pass by value or pass by reference?
JavaScript is always pass by value. For objects, the value passed is a reference, so a function can change the object's contents but cannot make the caller's variable point to a different object.
BeginnerQuick answer1 min read - What is an IIFE and why would you use one?
An IIFE (immediately invoked function expression) is a function that is defined and called in one go, like (function () { ... })(). It creates a private scope so variables inside do not leak out.
BeginnerQuick answer1 min read - What is the difference between a function declaration and a function expression?
A declaration is hoisted with its body, so you can call it before the line it appears on. An expression assigns a function to a variable, and the variable follows var, let or const rules, so calling it early fails.
BeginnerQuick answer1 min read - What is the difference between call, apply and bind?
All three set this for a function. call runs it now with arguments listed one by one, apply runs it now with an array of arguments, and bind returns a new function with this fixed, to be run later.
BeginnerQuick answer1 min read