# 05. BASICS | Number and Math in JavaScript

* * *

## Number

```javascript
const score = 400;
console.log(typeof(score)); // number

const balance = new Number(100);
console.log(typeof(balance)); // object


// Number properties and methods
// 1) toString()
console.log(balance.toString().length); // 3

// 2) toFixed() ==> how many digits will come after decimal
console.log(balance.toFixed(1)); // 100.0

// 3) toPrecision() ==> total kitni digits rahengi after round-off
const otherNumber = 123.8966
console.log(otherNumber.toPrecision(4)); // 123.9

// 4) toLocaleString()
const hundreds = 1000000
console.log(hundreds.toLocaleString('en-IN')); // 10,00,000

// 5) Number.MAX_VALUE

// 6) Number.MIN_VALUE

// 7) Number.MAX_SAFE_INTEGER

// 8) Number.MIN_SAFE_INTEGER
```

* * *

## Math

**<mark class="bg-yellow-200 dark:bg-yellow-500/30">Math is an object</mark>**. Math object has many properties and methods.

```javascript
// Math methods
console.log(Math.abs(-4)); // 4
console.log(Math.round(4.6)); // 5
console.log(Math.ceil(4.2)); // 5
console.log(Math.floor(4.9)); // 4
console.log(Math.min(4, 3, 6, 8)); // 3
console.log(Math.max(4, 3, 6, 8)); // 8

console.log(Math.random()); // gives a random number between 0 and 1

console.log(8/0); // Infinity
console.log(-8/0); // -Infinity

console.log(0/0); // NaN
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><code>typeof(NaN)</code> = number</div>
</div>

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><code>typeof(Infinity)</code> = number; <code>typeof(-Infinity)</code> = number</div>
</div>

* * *

Happy reading!
