In this function, when it is compared the lenght of the array it is used != operator and when it is comparing all elements of the array it is using !== operator. Why?! Thx.
var a = [1,2,3];
var b = [2,3,4];
function equalArrays(a,b){
if(a.length != b.length) return false;
for(var i = 0; i < a.length; i++)
if(a[i] ==! b[i]) return false;
return true;
}
means that two variables are being checked for both their value and their value type ( 8!== 8 would return false while 8!== "8" returns true). != only checks the variable's value ( 8!=
The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false . The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .
The strict equality operator ( === ) behaves identically to the abstract equality operator ( == ) except no type conversion is done, and the types must be the same to be considered equal. The == operator will compare for equality after doing any necessary type conversions.
The != operator compares the value or equality of two objects, whereas the Python is not operator checks whether two variables point to the same object in memory.
=
is an assignment operator, e.g. If you run var x = 1;
then x
will have the value of 1
.
==
(or !=
) is a comparison operator that checks if the value of something is equal to the value of something else. e.g. if(x == 1)
will evaluate to true
and so will if(x == true)
because 1
will evaluate to true
and 0
evaluate to false
.
===
(or !==
) is another comparison operator that checks if the value of something is equal to the value of, and is the same type as something else. e.g. if(x === 1)
will evaluate to true
however, if(x === true)
will evaluate to false
because 1
(the value of x
) is an integer and true
is a boolean.
The following are true:
false == false
false == null
false == undefined
false == 0
2 == "2"
The following are NOT true:
false === null
false === undefined
false === 0
2 === "2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With