+ 1

Why alert(!(4%2)) returns true?

I got it right in challenges but don't understand the logic behind it.

18th Jan 2022, 11:29 PM
Theoz
Theoz - avatar
1 ответ
+ 8
What's 4 % 2? zero right? in term of boolean, zero was false and other non-zero values were true. And then there's the unary logical NOT operator ! whose work was to invert whatever operand it was given, and since it is a logical operator, it gives back a boolean. So !( 4 % 2 ) is !( 0 ) means !( false ) means ... Voila!
19th Jan 2022, 12:20 AM
Ipang