JSFiddle - React, Tailwind, and code Playground
by juristr
HTML
<div id="outbox"></div>
JavaScript
/*
(C) Adapted from Secrets of the JavaScript Ninja by Jon Resig
*/
function assert(value, msg){
var outbox = document.getElementById('outbox');
outbox.innerHTML = outbox.innerHTML + '<br/><b>' + msg + ':</b> ' + value;
}
/*
This is the function being analyzed:
function outer(){
var a = 1;
function inner(){ /* does nothing */ }
var b = 2;
if (a == 1) {
var c = 3;
}
}
outer();
*/
assert(true,"|----- BEFORE OUTER -----|");
assert(typeof outer==='function', "outer() is in scope");
assert(typeof inner==='function', "inner() is in scope");
assert(typeof a==='number', "a is in scope");
assert(typeof b==='number', "b is in scope");
assert(typeof c==='number', "c is in scope");
function outer(){
assert(true,"|----- INSIDE OUTER, BEFORE a -----|");
assert(typeof outer==='function', "outer() is in scope");
assert(typeof inner==='function', "inner() is in scope");
assert(typeof a==='number', "a is in scope");
assert(typeof b==='number', "b is in scope");
assert(typeof c==='number', "c is in scope");
var a = 1;
assert(true,"|----- INSIDE OUTER, AFTER a -----|");
assert(typeof outer==='function', "outer() is in scope");
assert(typeof inner==='function', "inner() is in scope");
assert(typeof a==='number', "a is in scope");
assert(typeof b==='number', "b is in scope");
assert(typeof c==='number', "c is in scope");
function inner(){ /* does nothing */ }
var b = 2;
assert(true,"|----- INSIDE OUTER, AFTER inner() AND b -----|");
assert(typeof outer==='function', "outer() is in scope");
assert(typeof inner==='function', "inner() is in scope");
assert(typeof a==='number', "a is in scope");
assert(typeof b==='number', "b is in scope");
assert(typeof c==='number', "c is in scope");
if (a == 1) {
var c = 3;
assert(true,"|----- INSIDE OUTER, INSIDE if...