Home>Article>Web Front-end> How to determine odd and even numbers in javascript
In JavaScript, you can use the if statement, "%" and "==" operators to determine whether the value is divisible by 2, and then determine whether the value is an odd or even number. The syntax is "if(value%2= =0){Even number execution code;}else{Odd number execution code;}".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
How to find odd and even numbers in JavaScript
In JavaScript, you can use if statements, % and == operators to find odd and even numbers, example As follows:
Document
Output result:
##[Recommended learning:javascript advanced tutorial]
The above is the detailed content of How to determine odd and even numbers in javascript. For more information, please follow other related articles on the PHP Chinese website!