Surprised that global variable has undefined value in JavaScript

后端 未结 6 1119
情话喂你
情话喂你 2020-11-22 01:33

Today, I got completely surprised when I saw that a global variable has undefined value in certain case.

Example:

var value = 10;
functi         


        
6条回答
  •  孤城傲影
    2020-11-22 02:19

    I was running into the same problem even with global variables. My problem, I discovered, was global variable do Not persist between html files.

    
    
    

    I tried to reference myVar and myVarTwo in the loaded HTML file, but received the undefined error. Long story/day short, I discovered I could reference the variables using:

    
    
        
        
    
    

提交回复
热议问题