In the following JavaScript code snippet, I expect that the console
output be 3
but in both Chrome and Mozilla, it is 23. Why?
var status = ["Busy", "Preferred", "Available"];
console.log( status.length);
There's already a window.status
(a global variable named status
). Read more here .
When you're trying to set the array ["Busy", "Preferred", "Available"]
to your global variable, the window.status
setter will be invoked. So, window.status
property will contain the string "Busy,Preferred,Available"
.
So, yeah change the variable name or don't use global variables (please).
看起来status是Chrome和Firefox的保留变量,请尝试使用其他变量名。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.