2

Some SPECIAL words such as Object, Array, Function, Method, Number etc are not belong to keywords in Javascrpt: Reserved Keywords in Javascript.

But I have to use them carfully, they are not NORMAL words as object, array, method, number, foo ...

I'd like to know how many such SPECIAL words we have? Pls give me the list.

Community
  • 1
  • 1
John
  • 393
  • 2
  • 10

2 Answers2

4

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 = {};
var func = 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.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Thanks, BoltClock. where can I find all these built-in function/class types in JavaScript? – John Oct 09 '10 at 17:09
  • @Matt Ball, w3d gives two links are different from yours, any comments? – John Oct 10 '10 at 09:22
  • 1
    @John: Mozilla's JavaScript documentation is *official* as they are the developers and maintainers of the JavaScript scripting language. – BoltClock Oct 10 '10 at 09:31
  • @John: JavaScript is an implementation of the ECMA-262 language specification - [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript) - and yes, as BoltClock said, Mozilla (Foundation) is _the_ JavaScript developer: http://en.wikipedia.org/wiki/Javascript (see the sidebar on the right). – Matt Ball Oct 10 '10 at 13:27
  • Wikipedia is a bit misleading about what "JavaScript" is. So JavaScript is Mozilla's ES implementation, OK... But if you're going to say that instead of "javascript is a generic term for ES implementations, including Moz's JavaScript, MS's JScript, etc." then how the heck can you call V8 a "JavaScript Implementation?" Very misleading. – Dagg Nabbit Oct 10 '10 at 18:23
3

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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • I mean Function, not function. – John Oct 09 '10 at 09:43
  • @John Sorry, yes, "Function" (capital 'F') is a predefined object. – MrWhite Oct 09 '10 at 09:59
  • Matt Hall give me http://developer.mozilla.org/en/JavaScript/Reference/Global_Objects, which is different to your list, especially for Function, I am still somehow confused. – John Oct 10 '10 at 09:18
  • @John I have updated my answer, but 'Function' is included in both lists as a predefined global object. – MrWhite Oct 10 '10 at 18:15