JSFiddle - React, Tailwind, and code Playground

by tchaffee

HTML

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

JavaScript

var funcs = [];

// Outer function creates new scope.
function makeLog (j) {
  // Declare inner function using new scope.
  return function () {
    console.log('My value: ', j);
  }
}

for (var i = 0; i < 4; i++) {
  // Run makeLog, but the inner function doesn't run yet.
  funcs[i] = makeLog(i);
}

// Run each inner function.
funcs[1](); // logs 1
funcs[2](); // logs 2
funcs[3](); // logs 3