JavaScript comparison and logical operators

Comparison operator

OperatorDescriptionExampleOperation Result

##== Equal to 2 == 3 FALSE

=== Constantly equal (both values and types are compared) (2 === 2 TRUE) (2 === "2" FALSE )

!= Not equal to, can also be written as <> 2 == 3 TRUE

> Greater than 2 > 3 FALSE

< Less than 2 < 3 TRUE

>= Greater than or equal to 2 >= 3 FALSE

<= Less than or equal to 2 <= 3 TRUE

Comparison operators can also be used for string comparisons.

    php中文网(php.cn)  


##Logical operators

Operator

Explanation

ExampleOperation result

#&& Logical AND (and) x = 2 ; y = 6; x && y > 5 FALSE

|| Logical OR (or) x = 2; y = 6; , take the opposite side of logic x = 2; y = 6; !(x > y) TRUE

    php中文网(php.cn)  

Conditional Operator

JavaScript also includes conditional operators that assign values to variables based on certain conditions.

Syntax

variablename=(condition)?value1:value2

    php中文网(php.cn) 
年龄:

是否达到上学年龄?



Continuing Learning
||
php中文网(php.cn)
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!