Why Javascript Doesn't Include Reserved Keywords Such As "object", "array", "function", "number" ...?
Solution 1:
It all boils down to one thing, really: JavaScript is case sensitive. That's why it makes a distinction between Object
and object
.
Object
, Array
, Function
and Number
are not keywords, nor are they exactly "special" (whatever you think they mean) words.
They're nothing more than built-in function/class types in JavaScript (you can do a typeof
on them and see). You don't directly use them often now though since there are syntactic alternatives to creating objects of each of those types, for example:
var obj = {};
varfunc = function() {};
var arr = [];
var num = 123;
The others you mention (object
, array
, method
, number
, foo
) aren't keywords or "special" words either simply because, since as I say JavaScript is case sensitive, they mean nothing in JavaScript compared to their capitalized counterparts. Unless, of course, you give them meaning yourself by declaring variables with those names.
Solution 2:
Just to clarify, "function" is a reserved word, "Function" is a predefined object in the global scope.
The special words you list (although I'm not sure about "Method"?) are predefined JavaScript Classes and Objects in the global scope. They aren't necessarily reserved words because they aren't part of the language syntax and can, in some cases, be overridden. But yes, ordinarily they should not be used and should otherwise be treated the same way as 'reserved words'. See also Global Properties and Methods.
EDIT: With reference to the list provided at developer.mozilla.org/en/JavaScript/Reference/Global_Objects - this appears to be a list of the core JavaScript Objects, irrespective of whether the JavaScript engine is running in the browser or not. This is a sub-list of the list provided at About.com. Although why 'Boolean' is omitted from the list of Global Objects at About.com I don't know - this does appear to be an omission?
Other objects defined by the (Mozilla) browser/DOM are listed in the Gecko DOM Reference.
Post a Comment for "Why Javascript Doesn't Include Reserved Keywords Such As "object", "array", "function", "number" ...?"