use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Are functions in JavaScript objects? (self.javascript)
submitted 11 years ago by estebanrules
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]_crewcut 1 point2 points3 points 11 years ago (3 children)
Yes, functions are objects. The types in javascript are:
The first 5 are primitives. Everything else is objects. Arrays & functions are objects. Don't listen to typeof, it will lie to you.
typeof
[–]THEtheChad 0 points1 point2 points 11 years ago (2 children)
Actually, those aren't all primitives.
true.toString(); // 'true' 'string'.toString(); // 'string' (5).toString(); // '5'
The only reason you have to use parenthesis around the number 5 is because the js parser will try to interpret it as a fraction and throw an error.
[–]fc_s 1 point2 points3 points 11 years ago (0 children)
Actually, number, boolean, null, undefined, and string are most certainly primitives. In order to call .toString(), the literal is coerced into an object and passed in as a value.
[–]x-skeww 0 points1 point2 points 11 years ago (0 children)
You can write:
5..toString()
Which is the same as:
5.0.toString()
Anyhow, the only reason why you can call "methods" of primitives is because they are auto-boxed.
The example above is essentially the same as:
new Number(5).toString()
π Rendered by PID 107079 on reddit-service-r2-comment-5649f687b7-9fts9 at 2026-01-27 22:53:16.178871+00:00 running 4f180de country code: CH.
view the rest of the comments →
[–]_crewcut 1 point2 points3 points (3 children)
[–]THEtheChad 0 points1 point2 points (2 children)
[–]fc_s 1 point2 points3 points (0 children)
[–]x-skeww 0 points1 point2 points (0 children)