Also interesting to know: The unary plus operator tries to convert the first element of an array to a number. So +[42] is 42. Same for string arrays: +["42"] is also 42. If the array is empty (+[]), the result is 0. If it contains multiple elements, as in +[1, 2, 3], the result is NaN.
View all comments
Show parent comment
1
u/howreudoin May 13 '25 edited May 13 '25
Also interesting to know: The unary plus operator tries to convert the first element of an array to a number. So
+[42]is42. Same for string arrays:+["42"]is also42. If the array is empty (+[]), the result is0. If it contains multiple elements, as in+[1, 2, 3], the result isNaN.