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
Tweet