How to use Division / Operator In Javascript
In this approach we divide two numbers in JavaScript involves using the / operator to perform arithmetic division on numeric variables, resulting in their division.
Syntax:
a / b
Example: This example describes the division of 2 numbers using the / operator.
let a = 20;
let b = 10;
// Divide directlty
console.log(a/b); // 2
console.log(b/a); // 0.5
// Divide by using another variable
let c = a/b;
console.log(c); // 2
// Divide without any variable
console.log(20/10); // 2
console.log(10/20); // 0.5
Output
2 0.5 2 2 0.5
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
Contact Us