+ 1
"!==" what does it mean?
so I am having a hard time what this means: return ( number % 2 !== 0); mostly with the" !==". does it function the same way as "=" and "=="? so for example: (number % 2 !== 0) console.log(2); so would it be ( 2 % 2 !==0) the output should be 0. I am a bit confused, please help! thank you.
5 Respostas
+ 4
In JavaScript, the "!=="" operator is used for strict inequality comparison, which means that it compares two values and returns a Boolean value based on whether they are not equal in value or data type.
In the context of the code you provided, "(number % 2 !== 0)" means that it checks whether the remainder of the division of "number" by 2 is not equal to zero. If the remainder is not equal to zero, then it returns true; otherwise, it returns false.
+ 3
https://stackoverflow.com/questions/42517721/difference-between-and#:~:text=on%20this%20post.-,!%3D,being%20compared%20to%20each%20other.
+ 1
In python it is similar
Operator Meaning Example
==Is Equal To 3
== 5 gives us False
!=Not Equal To 3
!= 5 gives us True
+ 1
To understand what !== means you first need to know what === is.
In javascript if you use == in an if condition to compare between "1" and 1 then it will return true.
Even though they are different value types they still are equal.
But === (Strict equality) not only checks if two values are equal but also if they are the SAME type.
For example if you compare 1 and "1" with === then it will return false but if you compare 1 and 1 or "1" and "1" with === then it will return true
!== is exactly like === but the catch is... if it becomes true then it returns false and if it is false then it returns true.
So 1 and 1 compared with !== will return false while 1 and 2 return true... same thing when compared with "1" and 1.
0
Eren It is used for inequality comparison ....