I noticed strange issue.
Look at this jQuery:
$(function(){
status = 1;
status1 = 2;
$('body').append(status+' - '+status1);
});
As you can see output is:
- 2
So status
is system var for JavaScript or jQuery?
And is there any other vars like this?
JavaScript has global variables and in browsers, global variables are properties of the global object which is window
.
Now, window
itself has a couple of predefined properties and some of them are read-only, like window.status
[MDN] (this can also differ from browser to browser!). Creating a global variable with such a name will therefore fail (the variable already exists, but you cannot assign a new value to it).
You can find a list of predefined properties in the MDN documentation.
This one of the reasons why you should avoid global variables. If you use local variables (by declaring variables with var
and if necessary, put all your code in a function), you don't have this problem:
(function() {
var status = 'foo';
// ....
}());