JSFiddle - React, Tailwind, and code Playground

by LyndseyB

JavaScript

for(var i = 0; i < 10; i++) {
	// setTimeout waits for the next frame
  // once for loop has finished,
  // setTimeout has i as variable not as value
  // so it outputs 10
  setTimeout(function() {
  	// exists as memory address/reference not as value
  	console.log(i);
  }, 0);
}


// when we use let, it's block scoped
// and each value is passed as value not as reference