Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
Block Scopes { .. stuff .. }
are a bit different that js Function scopes.
Variables defined in a function scope
are restricted to their scope whereas variables defined in a block scope are not.
// example 1 //
var condition = true;
if (condition)
{
var msg = "Hello";
}
// you can still see and use this variable. Boo.
alert(msg);
// example 2 //
for(var i = 0; i < 5; i++)
{
// do stuff
}
// wait...how can I see 'i'? that's not right
alert(i);
// example 3 //
// let's use LET to fix that
var condition2 = true;
if (condition2)
{
let msg2 = "Hello";
}
// nope! No can do
//alert(msg2);
// example 4 //
function FooBar()
{
var msg3 = "foobar";
}
// NOPE! no can do either. this was defined in a function
//alert(msg3);