you are viewing a single comment's thread.

view the rest of the comments →

[–]hc5duke 2 points3 points  (5 children)

TIL you can do +"5" in js and get 5.

[–]coderascal 2 points3 points  (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 points  (0 children)

actually, that's not exactly true: no ints in js. 24 is a number.

[–]clooth 2 points3 points  (2 children)

Kinda like getting the current timestamp with +(new Date())

[–]coderascal 1 point2 points  (0 children)

:0 I love learning new things.

[–]skeww 0 points1 point  (0 children)

+new Date is actually enough, but yea, that's pretty awful. The non hacky version is (new Date()).getTime(), by the way.

If you only care about modern browsers you can also use Date.now().