window.variableName

前端 未结 6 1819
梦如初夏
梦如初夏 2020-11-28 06:45

I am going through some code and at the beginning of the script we have var emailID = email. Later on, the code refers to emailID by going window.emailID<

6条回答
  •  甜味超标
    2020-11-28 07:01

    Global Variables in JavaScript

    var no =10;
    function getNo()
       alert(no); // 10
    }
    getNo();
    

    When a global variable is set, it's added to the window object!

    var no =10;
    function getNo()
       alert(window.no); // 10
    }
    getNo();
    

    We can direct set window variable.

    function setNo(){
      window.no=100;
    }
    function getNo()
       alert(window.no); // 100
    }
    setNo();
    getNo();
    

提交回复
热议问题