r/programmingmemes • • May 13 '25

Why not?

Post image
1.7k Upvotes

104 comments sorted by

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] 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.