JavaScript Tutorial/Operators/Mod

Материал из Web эксперт
Перейти к: навигация, поиск

Mod operator in action

   <source lang="javascript">

<html> <head> <title>A Simple Page</title> <script language="JavaScript">

</script> </head> <body> </body> </html></source>


Modulus (%)

Modulus (%) operator returns only the remainder.

If either value is a string, an attempt is made to convert the string to a number.

For example, the following line of code



   <source lang="javascript">

var resultOfMod = 26 % 3;</source>


%= (Modulus Assignment)

The modulus assignment operator divides the value stored in the left variable by the right value. If value is a string, an attempt is made to convert the string to a number before performing the modulus and assignment.



   <source lang="javascript">

<html>

    <script language="JavaScript">
   
   </script>

</html></source>