Home >Web Front-end >JS Tutorial >Usage of % in js
JavaScript’s % operator is used to calculate the remainder of two numbers. The syntax is: num1 % num2. It has a wide range of applications, including remainder finding, parity checking, cryptography, and game development.
Usage of % operator in JavaScript
In JavaScript, the % operator is used to calculate the sum of two numbers remainder. It takes two numbers as arguments and returns the remainder after dividing the first number by the second number.
Syntax:
<code>num1 % num2</code>
Where:
Example:
<code class="javascript">console.log(10 % 3); // 1 console.log(22 % 5); // 2 console.log(47 % 7); // 6</code>
Note:
Application:
% operator is widely used in JavaScript, for example:
Sample application:
<code class="javascript">// 奇偶性检查 function isEven(number) { return number % 2 === 0; } // 模块化编程 function getModule(number, modulus) { return number % modulus; }</code>
The above is the detailed content of Usage of % in js. For more information, please follow other related articles on the PHP Chinese website!