How to use Division Assignment Operator In Javascript

This “/=” operator is used for division where we divide the variable’s value present in the left side to the value or variable present in the right side and that result get stored in left variable itself.

Syntax:

 leftOperand /= rightOperand;

Example: This example decribes division of two numbers using Division assignment operator

Javascript
// Creating a variable having value 40
let x = 40;

// Using subtract-and-operator
x /= 10.0;

// Printing the result
console.log(x); // 4

Output
4

JavaScript Program for Division of Two Numbers

In this article, we will see the basic approaches for the division of two numbers in JavaScript. The division is used in many languages, In JavaScript it can be done using some operators or some other methods.

Javascript has no data type such as integer, float, or double so we can directly use them via letting variables directly.

Example:

Let's take two numbers : 
a = 10
b = 5
here , a is dividend and b is divisor
a / b = 10 / 5 = 2

These are the following ways by which we can divide two numbers:

Table of Content

  • Using Division / Operator
  • Using Functions
  • Using Arrow function
  • Using Division Assignment Operator
  • Using Math.floor() for Integer Division

Similar Reads

Using Division / Operator

In this approach we divide two numbers in JavaScript involves using the / operator to perform arithmetic division on numeric variables, resulting in their division....

Using Functions

In this approach we are creating a custom function and passing parameters to them, dividing those parametres and returning the result....

Using Arrow function

We can make our custom Arrow function for division of numbers in which we can pass parameters and divide them accordingly and returns out the result of that division. It will work same as normal function but syntatically it differs from it....

Using Division Assignment Operator

This “/=” operator is used for division where we divide the variable’s value present in the left side to the value or variable present in the right side and that result get stored in left variable itself....

Using Math.floor() for Integer Division

In JavaScript, you might sometimes want to perform integer division where you discard the fractional part of the division result. This can be done using the Math.floor() function, which rounds down the result to the nearest integer....