JSFiddle - React, Tailwind, and code Playground

by tchaffee

HTML

<script src="https://rawgit.com/eu81273/jsfiddle-console/master/console.js"></script>

JavaScript

function runsAnyCallback(callback) {
  var i = 10;
  callback(); // logs 3!!!
}

function foo() {
  var i = 2;
  
  function bar() {
    i = i + 1;
    console.log ('value of i when bar is declared inside foo: ', i);
  }

  return bar;
}

var barFunc  = foo();

runsAnyCallback(barFunc); // logs 3!