What is Javascript closures? Explain closures with basic example

What is closures

Closures are functions that has access to the outer function's independent variables. It usually remembers the environment in which it was created.

Closures with basic example

function add(number1) {
  return function(number2) {
    return number1 + number2;
  };
}

var closuresFunc = add(300);
console.log(closuresFunc(200));

Output

500

Comments