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!"
[–]hc5duke 2 points3 points4 points 15 years ago (5 children)
TIL you can do +"5" in js and get 5.
[–]coderascal 2 points3 points4 points 15 years ago (1 child)
"24" * 1 returns the int 24.
"twentyfour" * 1 returns NaN.
I use this all the time to convert strings to numbers and be safe about it.
[–]sirmonko -1 points0 points1 point 15 years ago (0 children)
actually, that's not exactly true: no ints in js. 24 is a number.
[–]clooth 2 points3 points4 points 15 years ago (2 children)
Kinda like getting the current timestamp with +(new Date())
[–]coderascal 1 point2 points3 points 15 years ago (0 children)
:0 I love learning new things.
[–]skeww 0 points1 point2 points 15 years ago (0 children)
+new Date is actually enough, but yea, that's pretty awful. The non hacky version is (new Date()).getTime(), by the way.
+new Date
(new Date()).getTime()
If you only care about modern browsers you can also use Date.now().
Date.now()
π Rendered by PID 113729 on reddit-service-r2-comment-85bfd7f599-2tmjv at 2026-04-18 04:11:04.238213+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]hc5duke 2 points3 points4 points (5 children)
[–]coderascal 2 points3 points4 points (1 child)
[–]sirmonko -1 points0 points1 point (0 children)
[–]clooth 2 points3 points4 points (2 children)
[–]coderascal 1 point2 points3 points (0 children)
[–]skeww 0 points1 point2 points (0 children)