Javascript Odd Scoping Behavior

后端 未结 3 623
Happy的楠姐
Happy的楠姐 2021-01-22 07:21

I\'ve been going through Javascript function scope and have run into this:

var scope = \"global\";

function f(){
    console.log(scope);

    var scope = \"loca         


        
3条回答
  •  梦毁少年i
    2021-01-22 08:18

    Javascript sometimes behaves a bit differently from other languages. Take a look at http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html, they explain it a bit.

提交回复
热议问题