My vim syntax highlighting just lead me to believe that status
is a keyword in JavaScript.
Searching around all I can find are articles about window.status
in browser JavaScript. Is this the meaning of this 'keyword' status
or is there something different going on?
What is the keyword status
?
My vim syntax highlighting just lead me to believe that status
is a keyword in JavaScript.
Searching around all I can find are articles about window.status
in browser JavaScript. Is this the meaning of this 'keyword' status
or is there something different going on?
What is the keyword status
?
-
status is not a javascript keyword as far as I've been able to find - where does your information e from? the
status
inwindow.status
does not makestatus
a keyword ... it is aproperty
of window - see window.status "documentation" - perhaps you are thinking ofstatic
? – Jaromanda X Commented Apr 6, 2018 at 2:52 - I'm not seeing it in the specification: ecma-international/ecma-262/8.0/… – Andy Gaskell Commented Apr 6, 2018 at 2:57
-
"I just noticed that
status
is a keyword in JavaScript" I don't know where you got that information because it absolutely is not. – zzzzBov Commented Apr 6, 2018 at 3:02 - Ahh I see, let me reword my question, it was foolish to assume it was a keyword just because of my syntax highlighting. – Daniel Thompson Commented Apr 6, 2018 at 3:03
3 Answers
Reset to default 5This answer is actually incorrect. I probably confounded static
with status
. The Mozilla website has a page about the window.status
. It may have been done that way so you do not try to use that name as a variable. That way you would not inadvertently update the status bar of your browser. The feature doesn't work anymore, but I guess the vim editors is lagging.
In the Mozilla documentation (which is easier to read than the ECMA reference,) we find the status
keyword under the Future reserved keywords section.
So, it is viewed as a keyword.
However, JavaScript accepts reserved keywords in various places such as after a period as in:
a = {}
a.default = 123
a.status = 555
Here I set the default
and status
members of object a
even though these two names are viewed as reserved keywords in the language.
Actually, if you have been using Promise objects, you may have noticed the catch
keyword used as one of the possible callbacks:
Promise.all([a, b, c])
.then(...)
.catch(...) <-- this is a reserved keyword
.finally(...) <-- this is a reserved keyword
Here are the pertinent grammar entries:
Identifier :
IdentifierName but not ReservedWord
MemberExpression :
PrimaryExpression
MemberExpression [ Expression ]
MemberExpression . IdentifierName <-- look at this one
MemberExpression TemplateLiteral
SuperProperty
MetaProperty
new MemberExpression Arguments
An IdentifierName
is any identifier (more or less [A-Z_$][A-Z_0-9$]*
, plus all Unicode characters... they actually follow the Unicode definition of an identifier.) That includes reserved keywords.
As we can see, you are not supposed to start an expression with a ReserverWord
, except for a new exception like new
and super
(not shown here, see SuperProperty
.)
So in strict mode (i.e. in a node module) you should get an error if you write:
status = 123
In non-strict mode, status
is not a reserved keyword and therefore it is allowed.
One way to make sure that it works when you access variable members is to use the array syntax. For example:
a['default'] = 123
a['status'] = 555
Also that way the names do not get highlighted as reserved keywords by your editor.
If you play around in your console. You can do the following:
-> status
<- ""
-> window.status
<- ""
-> status='333'
<- "333"
-> status
<- "333"
-> window.status
<- "333"
This to me indicates that the keyword status
is simply an alias for the window.status
property. What exactly window.status
does I am not sure.
EDIT: After reading the ment below, I realized that properties of the windows object are essentially global. So this makes status the same as window.status and NOT an alias as I mention above.
See this Stack Overflow about the window object: Is window really global in Javascript?
Officially 'status' may be defined as a keyword or not; but I landed in trouble when I tried to use it as an identifier. Here is a snippet:
<html>
<body>
status IS a key word.
<br/>
<span id="stat1"></span></div>
<br/>
<span id="stat2"></span></div>
<script>
var status = document.getElementById("stat1");
status.innerHTML = "foo";
console.log(status.innerHTML);
var xtatus = document.getElementById("stat2");
xtatus.innerHTML = "bar";
console.log(xtatus.innerHTML);
</script>
</body>
</html>
The content is not displayed until you agree to change the name. The console shows 'undefined' instead of 'foo'.