Home >Web Front-end >JS Tutorial >[JavaScript Tutorial] JavaScript comparison and logical operators
JavaScript Comparison and Logical Operators
Comparison and logical operators are used to test true or false.
Comparison Operators
Comparison operators are used in logical statements to determine whether variables or values are equal.
09ca8e761b2ed2b2e14bae57a6a1bd6c Greater than x>8 false Example»
4bd7243d1baa72969ffbe765e7f3a973= Greater than or equal to x>=8 false Example»
5a35e1a87deb3536534f41bc0b5c3007 1) is true
|| or (x==5 || y==5) is false
! not !(x==y) is true
Conditional Operator
JavaScript also contains functions based on certain conditions Conditional operator for assigning values to variables.
Syntax
variablename=(condition)?value1:value2
Example
Example
If the value in the variable age is less than 18, assign the value "age is too young" to the variable voteable, otherwise assign the value "age has reached".
voteable=(age<18)?"年龄太小":"年龄已达到";
The above is the content of [JavaScript Tutorial] JavaScript comparison and logical operators. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!