Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does % do in JavaScript?

Tags:

javascript

What does the % do in JavaScript?

A definition of what it is and what it does would be much appreciated.

like image 662
fancy Avatar asked Jan 17 '12 19:01

fancy


People also ask

What is '$' in JavaScript?

Updated on July 03, 2019. The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.

What does ~~ mean in JavaScript?

JavaScript Learn JavaScript Quick Course Beginners The “double tilde” (~~) operator is a double NOT Bitwise operator. Use it as a substitute for Math. floor(), since it's faster.

What are the 4 types of JavaScript operators?

JavaScript includes operators that perform some operation on single or multiple operands (data value) and produce a result. JavaScript includes various categories of operators: Arithmetic operators, Comparison operators, Logical operators, Assignment operators, Conditional operators.


1 Answers

It's a modulo operator. See this documentation or the specification for more information on JavaScript arithmetic operators.

% (Modulus)

The modulus operator is used as follows:

var1 % var2

The modulus operator returns the first operand modulo the second operand, that is, var1 modulo var2, in the preceding statement, where var1 and var2 are variables. The modulo function is the integer remainder of dividing var1 by var2. For example, 12 % 5 returns 2. The result will have the same sign as var1; that is, −1 % 2 returns −1.

like image 176
nulltoken Avatar answered Sep 22 '22 15:09

nulltoken