Horje
Division Assignment(/=) Operator in JavaScript

JavaScript Division Assignment Operator in JavaScript is represented by “/=”. This operator is used to divide the value of the variable by the value of the right operand and that result is going to be assigned to the variable. This can also be explained as dividing the value of the variable by an expression and assigning that result to the variable.

Syntax:

a /= b
or
a = a / b

Example 1: In this example, we will use the division assignment operator.

Javascript

let x = 18;
x /= 3;
console.log(x);
  
x /= 2;
console.log(x);
  
x /= 0;
console.log(x);


 

Output

6
3
Infinity

Example 2: In this example, we will use the division assignment operator.

Javascript

let a = 18;
a /= 3;
console.log(a);
  
a /= 'bar';
console.log(a);

Output

6
NaN

We have a complete list of Javascript Assignment Operators, Please check this article Javascript Assignment Operator.

Supported Browser:

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 3
  • Safari 1


Reffered: https://www.geeksforgeeks.org


JavaScript

Related
Count occurrences of all items in an array in JavaScript Count occurrences of all items in an array in JavaScript
How does Backbone.js relate to "traditional" MVC ? How does Backbone.js relate to "traditional" MVC ?
NuxtJS NuxtJS
JavaScript String at() Method JavaScript String at() Method
How to check for "undefined" value in JavaScript ? How to check for "undefined" value in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12