Javascript multiple assignment statement

前端 未结 6 1955
小鲜肉
小鲜肉 2021-01-03 10:28

I saw that line in some code

window.a = window.b = a;

How does it work?

Does the following always return true?

win

6条回答
  •  耶瑟儿~
    2021-01-03 11:15

    The a and b properties on the window are being assigned to the value of a. Yes, if this code is executed in the global scope, a and window.a are the same.

    var a = "foo";
    
    //window.a and a are the same variable
    window.a = "bar";
    a; //bar
    
    function f(){
        var a = "notfoo";
    
        //window.a is a different variable from a, although they may take the same value
        window.a = "baz";
        a; //notfoo
    }
    

提交回复
热议问题