JS Visualizer – Visualize Context, Hoisting, Closures, and Scopes in JavaScript
javascriptvisualizer.com
javascriptvisualizer.com
It was a great complementary tool explaining some simple algo to students.
http://worrydream.com/LearnableProgramming/
Inventing on principle: https://vimeo.com/36579366
It is set in the world of computing before UNIX was out of Bell Labs.
Seems like someone's already reported the issue, though.
For example this doesn't print what you expect:
for (var i = 0; i < 3; i++) {
var text = 'number ' + i;
setTimeout(function() {
console.log(text);
}, i * 1000);
}
But flipping var to let will fix it. The bug is that var is not block-scoped so everything refers to the same `text` variable which gets mutated by the next iteration.I was hoping their demo would be good for explaining this bug but it seems to be broken.
variables in javascript are not block scoped, but functionally scoped.
the let keyword introduces block scope to javascript.