After taking over a project from someone else, written in Javascript.
One line I see everywhere is if statements using !+msg. From testing I can see that it checks to see if there is more than one word or not, but I was hoping someone could explain why this works. Thanks!
1 Answer
The + operator coerces its operand to a number, and the ! operator coerces its operand to a boolean value and inverts its sense (false -> true or vice-versa). Thus !+msg means, "if the value of msg interpreted as a number is 0 or NaN, the value should be true, otherwise false."
1 Comment
Bread
Makes sense! Thank you!
msgmight contain, or why.