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.
Given x=5, the following table explains the comparison operators:
Operator | Description | Example |
---|---|---|
== | is equal to | x==8 is false |
=== | Congruent (value and type) | x===5 is true; x==="5" is false |
!= | is not equal to | x!=8 is true |
> | is greater than | x>8 is false |
< | is less than | x<8 is true |
is greater than or equal to | x>=8 is false | |
is less than or equal to | x<=8 is true |
if (age<18) document.write("Too young");
We will introduce more about it in the following chapters Knowledge of conditional statements.
Logical Operators
Logical operators are used to determine the logic between variables or values. Given x=6 and y=3, the following table explains the logical operators:Conditional operators
JavaScript also includes conditional operators that assign values to variables based on certain conditions.
Syntax
variablename=(condition)?value1:value2
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".
php中文网(php.cn) 点击按钮检测年龄。
年龄:是否达到投票年龄?
Run the program and try it
- Course Recommendations
- Courseware download
-
IntermediateFront-end Vue3 actual combat [handwritten vue project]
2857 people are watching -
ElementaryAPIPOST tutorial [Popularization of technical concepts related to network communication]
1795 people are watching -
IntermediateIssue 22_Comprehensive actual combat
5521 people are watching -
ElementaryIssue 22_PHP Programming
5172 people are watching -
ElementaryIssue 22_Front-end development
8713 people are watching -
IntermediateBig data (MySQL) video tutorial full version
4525 people are watching -
ElementaryGo language tutorial-full of practical information and no nonsense
2794 people are watching -
ElementaryGO Language Core Programming Course
2814 people are watching -
IntermediateJS advanced and BootStrap learning
2563 people are watching -
IntermediateSQL optimization and troubleshooting (MySQL version)
3374 people are watching -
IntermediateRedis+MySQL database interview tutorial
2963 people are watching -
ElementaryDeliver food or learn programming?
5708 people are watching
Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
- About us Disclaimer Sitemap
- php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
Description | Example | |
---|---|---|
and | (x < 10 && y > 1) is true | |
or | (x==5 || y==5) is false | |
not | !(x==y) is true |