Home  >  Article  >  Web Front-end  >  [JavaScript Tutorial] JavaScript comparison and logical operators

[JavaScript Tutorial] JavaScript comparison and logical operators

黄舟
黄舟Original
2016-12-24 15:08:26950browse

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)!


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