Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch 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



Government Jobs Opening


...