Monday, September 14, 2015

JavaScript - Tips 1 - Hoisting

var myVar = "my global variabl"
function hoistingSampleAsInterpreted()
{
var myVar;
alert(myVar); //value is undefined
myVar = "my local variable"; //value is not undefined
alert(myVar);
}
//Hoisting - Variable declarations moved to top of function by JavaScript engines
var myVar = "my global variabl"
function hoistingSampleAsInterpreted()
{
var myVar = "my local variable";
alert(myVar);
}

No comments:

Post a Comment