Redeclaring a javascript variable

后端 未结 8 1776
耶瑟儿~
耶瑟儿~ 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条回答
  •  情歌与酒
    2020-11-29 06:22

    It is pretty simple re-declaring doesn't actually affect anything, you just have to remember that if you reassign value within scope then the reassigned value is limited to scope and outside of scope it will still be globally declared value

    var page =1 ;
    function htmlcode(page) { 
    page = "keka";
    console.log("inside " + page);
    }
    
    htmlcode(page);
    console.log("inside " + page);
    
    Output : inside keka
             inside 1
    

提交回复
热议问题