Why variable hoisting after return works on some browsers, and some not?

前端 未结 5 1120
执笔经年
执笔经年 2020-11-22 12:11
alert(myVar1);
return false;
var myVar1;

Above code throws error in IE, FF and Opera stating that return statement has to come in the function. But

5条回答
  •  遇见更好的自我
    2020-11-22 13:07

    It is JavaScript Hoisting thing, Simply in other words, we are trying print the value of the variable , which is not holding any value

    Javascript will render the above code as:-

    var myVar1
    alert (myVar1)
    return false

    To clarify more i refered the link javascript hoisting: http://www.ufthelp.com/2014/11/JavaScript-Hoisting.html

提交回复
热议问题