Redeclaring a javascript variable

后端 未结 8 1785
耶瑟儿~
耶瑟儿~ 2020-11-29 05:33

In this tutorial there is written:

If you redeclare a JavaScript variable, it will not lose its value.

Why should I redeclare a variable? Is it

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 06:11

    It's nothing more than a reminder that if you do this:

    var x=5;
    var x;
    alert(x);
    

    Result will be 5.

    If you re-declare variable in some other languages for example - result will be undefined, or NaN, but not in javascript.

提交回复
热议问题