vikramlc / Javascript

0 stars 0 forks source link

Numbers and Strings #16

Open vikramlc opened 4 years ago

vikramlc commented 4 years ago

image

Number.MAX_SAFE_INTEGER
9007199254740991

Math.pow(2, 53)
9007199254740992

Math.pow(2, 54)
18014398509481984

Math.pow(2, 100)
1.2676506002282294e+30

Math.pow(2, 65)
36893488147419103000

Number.MIN_SAFE_INTEGER
-9007199254740991

Number.MAX_VALUE
1.7976931348623157e+308

Number.MIN_VALUE
5e-324
vikramlc commented 4 years ago

Floating Point Precision:

0.2 + 0.4
0.6000000000000001

(0.2 + 0.4) === 0.6
false

(1).toString(2);
"1"

(5).toString(2);
"101"

(1/5).toString(2);
"0.001100110011001100110011001100110011001100110011001101"

(0.2).toString(2);
"0.001100110011001100110011001100110011001100110011001101"

(0.2).toFixed(20);
"0.20000000000000001110"

(0.2).toFixed(2);
"0.20"

(20.2).toFixed(20);
"20.19999999999999928946"

20.2 * 100
2020

2020.0
2020
vikramlc commented 4 years ago

Big Int:

Number.MAX_SAFE_INTEGER
9007199254740991

9007199254740991 + 10
9007199254741000

9007199254740991 + 100
9007199254741092

9007199254740991n + 100n
9007199254741091n

parseInt(9007199254740991n) + 1000
9007199254741992

10n * 3n
30n

10n/2n
5n

10n - BigInt(3)
7n
vikramlc commented 4 years ago

Math operations:

function randomIntBetween(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min);
}

console.log(randomIntBetween(1, 20); // 17
vikramlc commented 4 years ago

Strings:

`${1}`
"1"
'hello'.big
ƒ big() { [native code] }
'hello'.big()
"<big>hello</big>"
'hello'.toLocaleUpperCase
ƒ toLocaleUpperCase() { [native code] }
'hello'.toLocaleUpperCase()
"HELLO"
'hello'.toLowerCase()
"hello"
'hello'.toUpperCase()
"HELLO"
'hello'.startsWith('he');
true