Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


How do get JavaScript closures work?


Whenever you see the function keyword within another function, the inner function has access to variables in the outer function.

 

function foo(x) {
  var tmp = 3;

  function bar(y) {
    alert(x + y + (++tmp)); // will alert 16
  }

  bar(10);
}

foo(2);

asked Jun 30, 2015 in JAVASCRIPT by rajesh
0 votes
13 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...