23 lines
741 B
Markdown
23 lines
741 B
Markdown
---
|
||
title: Finding a Remainder in JavaScript
|
||
localeTitle: Поиск остатка в JavaScript
|
||
---
|
||
Оператор _остатка_ `%` дает остаток от деления двух чисел.
|
||
|
||
## пример
|
||
```
|
||
5 % 2 = 1 because
|
||
Math.floor(5 / 2) = 2 (Quotient)
|
||
2 * 2 = 4
|
||
5 - 4 = 1 (Remainder)
|
||
```
|
||
|
||
## использование
|
||
|
||
В математике число может быть проверено четным или нечетным, проверяя остаток от деления числа на 2.
|
||
```
|
||
17 % 2 = 1 (17 is Odd)
|
||
48 % 2 = 0 (48 is Even)
|
||
```
|
||
|
||
**Примечание.** Не путайте его с _модулем._ `%` Не работает с отрицательными числами. |