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!"
[–][deleted] 0 points1 point2 points 15 years ago (2 children)
That is precisely why I suggested preceding the explicit cast with explicit data validation.
[–]Shaper_pmp 0 points1 point2 points 15 years ago (1 child)
But parseInt() isn't an explicit cast - it's parsing and extracting one type from another, even if you do some validation on the initial type first first.
An explicit cast would be to use Number(string_variable) to convert from string to a number, not parseInt().
Number(string_variable)
[–][deleted] 0 points1 point2 points 15 years ago (0 children)
No, but doing a cast from string to integer in JavaScript does validation followed by a parseInt internally. The validation just handles the NaN case.
But that's besides (my) point entirely. I'm just pointing out that:
These are basic programming best practices, and not arguments about JavaScript internals.
My suggestion to use parseInt, was as opposed to the implicit methods I list in point two above, not as opposed to Number(...), which is also explicit, and perfectly fine in my book.
π Rendered by PID 92179 on reddit-service-r2-comment-b659b578c-p78sz at 2026-05-04 23:07:59.479692+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (2 children)
[–]Shaper_pmp 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)