Usage of == and ===, &&, || and other operators in Vue





Commonly used operators



&&

When both conditions are true, the result is true;
if one of the conditions is false, the result is false;
when the first condition is false, the subsequent conditions are no longer judged



	



||

As long as one condition is true, the result is true;
when both conditions are false, the result is false;
when one condition is true, the following conditions are no longer judged

	



!=

! Negation operator, used to compare or judge whether the two are not equal (the value of the two variables)

value is false, !value is rue;
value is true, !value is false.

	


==

==operator only requires comparing the values ​​of two variables for equality

	
<template>
    <div>
        657=='657' {
   
   { 657=='657' }}   // true
        <br/>
        657==='657' {
   
   { 657==='657' }}	// false
    </div>
</template>




===

===The operator requires both variables to have the same value and type

For the special value NaN (Not a Number), it means not a number. If NaN is compared with any number (including itself), it will return false, so it is best to use the isNaN() function to judge NaN; for undefined and null, both Compared with the value of , it will return true.


	NaN == 6; 			// 返回 false
	NaN === NaN; 		// 返回 false
	null == undefined; 	// 返回 true
	null === undefined; // 返回 false
	

  • Otherwise it is treated as the string true and the string 657.



Summarize


&& : and (execute when true)
|| : or (execute when false)
! : Reverse evaluation (negation operator, != means not equal)
== : used to compare or judge whether the two are equal (values ​​of two variables), and the data type can be automatically converted during comparison;
=== : used For a stricter comparison, in addition to judging whether the data are equal, it will also judge whether the data types of the two are the same (the value and type of the two variables). If they are not the same, the data type will not be converted, and the result will return false.















Note:
Likes, comments, and reprints are welcome. Please give the link to the original text in an obvious place on the article page
. Those who know, thank you for reading my article in the vast crowd.
Where is the signature without personality!
For details, please follow me
and continue to update

Scan to have a surprise!
© 2022 06 - Guyu.com | [Copyright infringement must be investigated]

Guess you like

Origin blog.csdn.net/weixin_49770443/article/details/125504225