Let's play a little bit with JavaScript functions!

1. Can we write any code after return statement?
  • Yes
  • No

0 voters

  1. What is a closure?
  2. What will be the Output of following code?

function createHelloWorld(a) {
return function () {
return console.log(a);
};
}

const innerFunction = createHelloWorld(“hello world”);
innerFunction();

function createHelloWorld(a) {
return function () {
return console.log(a);
};
}

const innerFunction = createHelloWorld(“hello world”);
innerFunction();

o/p - hello world

1 Like
  1. No
  2. A closure in JavaScript is a combination of a function and the lexical environment within which that function was declared
  3. hello world
1 Like
  1. A closure is a feature of JavaScript that allows inner functions to access the outer scope of a function.
  2. output-hello world
1 Like

output- hello world

  1. a closure is a feature of javaScript that allows inner functions to access the outer scope of function.
  2. No
1 Like
  1. Closure is allow inner functions to access the outer scope of a function.
  2. const innerFunction = createHelloWorld(“hello world”);
1 Like
  1. A closure is a feature of JavaScript that allows inner functions to access the outer scope of a function.
    3.o/p : hello world
1 Like