Home >Web Front-end >JS Tutorial >Brief explanation of the difference between = = (equal) and = = = (all equal) in Javascript_Basic knowledge

Brief explanation of the difference between = = (equal) and = = = (all equal) in Javascript_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:36:471194browse

What is the difference between = = (equal) and = = = (all equal) in Javascript?

Let’s look at two examples first:

var n='100' ;

if(n==100)

 { 

alert('equal to');

}

else

                                        

alert('not equal to');

}

The result is "equal to";

When judging whether strings are the same,

var n=false;

if(n=='false')

                                                                              

alert('equal to');

         }

else

                                                             

alert('not equal to');

}

The result is "not equal to".

Reason: === When judging whether two values ​​are the same, it will first judge whether the data type is consistent. If the data type is consistent, it will continue to judge whether the content is the same. == When judging, the data type will be ignored and the judgment will be made directly. The content switch uses full equal judgment

In js, undefined and null are equal if == is used, and unequal if === is used.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn