Skip to content

Instantly share code, notes, and snippets.

JavaScript Review

Closure

Since JavaScript allows inner function such as Event Handler or Async Call, the inner function will have access to the variables defined in the outer function. The most interesting part of closure is that the inner function have reference to those variables even after the outer function has returned. This means if those varialbes value has changed, the innner function will see the changed value.

For example:

function run(){
    for(var i=0; i<5; i++){
 setTimeout(()=&gt;{