1

I see parseInt() and parseFloat() when I hit TAB in the console.

I can just type:

parseInt('123asd');

But where are these located?

ajsie
  • 77,632
  • 106
  • 276
  • 381

2 Answers2

8

They are properties of the global object. (built-in functions)

In the case of the browser, this is window.

Dominic Barnes
  • 28,083
  • 8
  • 65
  • 90
  • Or a different global object if you're not in a browser DOM (http://stackoverflow.com/questions/1162998/how-can-i-add-an-object-property-to-the-global-object-in-rhino-javascript). – bdukes Nov 10 '10 at 20:24
  • @Dominic "... they are part of ..." could be misinterpreted or cause confusion. A better phrasing would be: "They are properties of the Global object". Also, note that in writing it is best to capitalize the word "Global", because parseInt and parseFloat are, technically, also global objects. – Šime Vidas Nov 10 '10 at 20:24
  • Also, `parseInt` and `parseFloat` are not technically part of the DOM, they are [built-in functions](http://ecma262-5.com/ELS5_HTML.htm#Section_4.3.25), part of the ECMAScript standard. The BOM/DOM are part of the [host environment](http://ecma262-5.com/ELS5_HTML.htm#Section_4.3.8)... – Christian C. Salvadó Nov 10 '10 at 21:10
  • @Šime: Not convinced about your capitalization comment: the spec refers to it without capitals, except in headings (where everything is capitalized). – Tim Down Nov 10 '10 at 23:18
  • @Tim I tend to think of the Global object as God, so it comes naturally to me to capitalize it. :) But don't things that are unique get capitalized in the English language? For example, the Internet. – Šime Vidas Nov 10 '10 at 23:32
  • @Šime: It's a slightly complicated topic, and even as an enthusiastic native English speaker I'm not sure of the rules, since the principle of capitalizing a unique noun is not consistently applied. Even "the Internet" is not universal: "the internet" is becoming more common (http://en.wikipedia.org/wiki/Internet_capitalization_conventions#The_argument_for_common_noun_usage) – Tim Down Nov 10 '10 at 23:46
  • @Tim Then I guess it's a matter of preference. BTW I am capitalizing it for the same reason that I'm capitalizing constructor function names... to reduce confusion. (Because there is only one Global object, but many global objects.) – Šime Vidas Nov 11 '10 at 01:00
2

parseInt and parseFloat are attached to the "Global" javascript object therefore they are available in all contexts.

Barry
  • 446
  • 2
  • 7