The difference between! = And! ==

In this function, when it is compared, the length of the array is used! = The operator, and when it compares all elements of the array, it uses the operator! ==. What for?! thank.

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;

}

+4
source share
5 answers

=is an assignment operator, for example. If you run it var x = 1;, it xwill make a difference 1.

==(or !=) - a comparison operator that checks if the value of something is equal to the value of something else. for example, it if(x == 1)will be evaluated before true, and therefore it will be if(x == true), because it 1will evaluate before trueand 0for evaluation false.

=== ( !==) - , , - , , - . if(x === 1) true, if(x === true) false, 1 ( x) , true .

+2

(===) , .

:

false == false
false == null
false == undefined
false == 0
2 == "2"

:

false === null
false === undefined
false === 0
2 === "2"
+9

!= . !== , , .

, , , . . , , 5 5:

if( '5' !== 5 ){
    return false
}else{
    return true;
}

false, . !=, :

if( '5' != 5 ){
    return false;
}else{
    return true;
}

true.

, , :

JavaScript , . :

  • , , .

  • , ( ). NaN , NaN. .

  • , .

  • , .

  • Undefined == ( ===). [.. (Null == Undefined) , (Null === Undefined) ]

: fooobar.com/questions/997/...

+3

! == true, .

: W3Schools

0

!== , , (8!==8 false, 8!=="8" true). != (8!=8 8!="8" false).

0

Source: https://habr.com/ru/post/1671076/


All Articles