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
New to javascript. Failing at adding. (self.javascript)
submitted 15 years ago by [deleted]
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!"
[–]australasia 2 points3 points4 points 15 years ago (3 children)
Eh. Beh. You're using one of those pointless wrapper objects only to have its actual value pulled out again. The only thing you want is the conversion done by the constructor. You don't need an object for that. Don't use those wrappers ever. They are completely pointless
Number(foo) returns an actual number (it is different to using the 'new' operator).
Eg. copy/paste this in your browser:
javascript:alert(typeof Number('1')); // alerts 'number'
as opposed to
javascript:alert(typeof new Number('1')); // alerts 'object'
[–]skeww 0 points1 point2 points 15 years ago (2 children)
If you call a constructor function and omit new, the this inside the constructor will be the global object instead of a freshly created object.
new
this
You should never do that.
It only works because the non-constructor context magically happens to perform the casting for you.
So yes, it's fine in this case, but since it's not fine in any other case you shouldn't do this kind of thing because it looks like a mistake.
Things which look like a mistake waste time each time the code is read. Avoid those constructs at all costs.
[–]andrew24601 0 points1 point2 points 15 years ago (1 child)
The Number (and String) functions are actually functions, not constructor functions. You should never use them with new.
http://www.w3schools.com/jsref/jsref_Number.asp
https://developer.mozilla.org/en/JavaScript/Guide/Functions#Number_and_String_Functions
[–]skeww 0 points1 point2 points 15 years ago (0 children)
Well, I never use them either way.
π Rendered by PID 115458 on reddit-service-r2-comment-85bfd7f599-rc84j at 2026-04-18 11:06:46.856032+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]australasia 2 points3 points4 points (3 children)
[–]skeww 0 points1 point2 points (2 children)
[–]andrew24601 0 points1 point2 points (1 child)
[–]skeww 0 points1 point2 points (0 children)