Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 1.04 KB

README.md

File metadata and controls

28 lines (21 loc) · 1.04 KB

JS Interview Questions


Question Answer
What is closure in JavaScript? Answer
Explain event delegation in JavaScript. Answer
What are the differences between let, var, and const? Answer

Closure in JavaScript

Closure is a fundamental concept in JavaScript where a function retains access to its lexical scope, even after the function has finished executing. It means the function 'remembers' its surrounding scope's variables and parameters, even if it's called outside of that scope.

Example:

function outerFunction() {
  let outerVariable = 'I am from the outer function';
  
  return function innerFunction() {
    console.log(outerVariable);
  }
}

let newFunction = outerFunction();
newFunction(); // Output: I am from the outer function