Today I Learned

hashrocket A Hashrocket project

Javascript's Unary Plus Operator

Today I learned about the unary plus (+) operator. It attempts to convert its operand into a number, so it's basically a shorthand for Number() (and uses the same rules around number coercion).

+"7"
// 7
+5
// 5

+true
// 1
+false
// 0
+null
// 0
+undefined
// NaN
+[]
// 0

Docs

See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.