Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '/=' operator mean in JavaScript?

Tags:

javascript

I came across this looking at the source for some physics animations in JavaScript found here on github where he's written this

if (this._position < 0) this._position /= 3;

A quick Google yielded nothing, anyone know?

like image 938
bigmadwolf Avatar asked Feb 13 '16 13:02

bigmadwolf


People also ask

What are operators in JavaScript?

In JavaScript, an operator is a special symbol used to perform operations on operands (values and variables). For example, 2 + 3; // 5. Here + is an operator that performs addition, and 2 and 3 are operands.

What does the === operator mean in JavaScript?

The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result.

What are the 7 types of operators?

In Python, there are seven different types of operators: arithmetic operators, assignment operators, comparison operators, logical operators, identity operators, membership operators, and boolean operators.


1 Answers

The operator is shorthand division operator. It is equivalent to

this.position = this.position / 3;

The division will be performed first and then the result will be assigned to the dividend.

Quoting from MDN

The division assignment operator divides a variable by the value of the right operand and assigns the result to the variable.

like image 71
Tushar Avatar answered Oct 08 '22 10:10

Tushar