JavaScript(JS) Numbers

www.igift‮aedi‬.com

In JavaScript, numbers are a primitive data type that represent numeric values. There are two types of numbers in JavaScript:

  1. Integer numbers: which are whole numbers (positive, negative, or zero) without any decimal points.

  2. Floating-point numbers: which are numbers with decimal points, and can represent fractions or very large or very small numbers using scientific notation.

Here are some examples of numbers in JavaScript:

let myInt = 42; // integer number
let myFloat = 3.14; // floating-point number
let myScientific = 1.23e6; // scientific notation: 1.23 x 10^6

You can perform various mathematical operations on numbers in JavaScript, such as addition, subtraction, multiplication, and division, using arithmetic operators (+, -, *, and /). Here's an example:

let x = 10;
let y = 5;
let sum = x + y; // addition
let diff = x - y; // subtraction
let product = x * y; // multiplication
let quotient = x / y; // division

console.log(sum); // Output: 15
console.log(diff); // Output: 5
console.log(product); // Output: 50
console.log(quotient); // Output: 2

It's important to note that JavaScript numbers have a limited precision due to the way they are represented internally. This means that some operations with floating-point numbers may not produce the expected results due to rounding errors. It's important to be aware of this when working with numbers in JavaScript.