-1

For what and how is used "x % 2 == 0" in JavaScript i will be happy if you tell me Have a nice day!

Alexander
  • 7
  • 2
  • 2
    Does this answer your question? [Testing whether a value is odd or even](https://stackoverflow.com/questions/6211613/testing-whether-a-value-is-odd-or-even) – lawrence-witt Jan 14 '21 at 21:16
  • It checks if a value is even. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder – β.εηοιτ.βε Jan 14 '21 at 21:16
  • `%` is the modulo operator and it performs remainder division. if you know whether a division operation results in a remainder, you can deduce whether a number is even or odd if you do the division by 2 and check for a remainder of `0`. – Scott Marcus Jan 14 '21 at 21:16
  • Welcome to SO! This problem is covering topics that are probably already very well represented on the site and could most likely have been discovered with some prior research; as such I imagine it may be closed. As some guidance: [`%` is the remainder operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder) and [`==` is a weak equality check](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality). As such, this code is checking if the variable `x` divided by `2` leaves a remainder of `0` (evenly divides). – Alexander Nied Jan 14 '21 at 21:18
  • As a new user, I'd recommend visiting the [ask] help page for tips on forming your questions. Good luck, and happy coding! – Alexander Nied Jan 14 '21 at 21:20

1 Answers1

-2

To check if number x is even.

x % 2 === 1 checks if it is odd.

It uses a modulo (reminder) operator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder

croraf
  • 2,926
  • 2
  • 22
  • 37