-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJS_Number.js
71 lines (56 loc) · 1.75 KB
/
JS_Number.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// JavaScript Numbers
// JavaScript has only one type of number. Numbers can be written with or without decimals.
let X=3.12; // A number with decimals
let y=4;// A number without decimals
console.log(X,y);
// Extra large or extra small numbers can be written with scientific (exponent) notation:
let a=123e4;
let b=1231e-5;
console.log(a,b);
// Integer Precision
// Integers (numbers without a period or exponent notation) are accurate up to 15 digits.
let x = 999999999999999; // x will be 999999999999999
let Y = 9999999999999999; // y will be 10000000000000000
console.log(x,Y);
// Floating point arithmetic is not always 100% accurate:
let m=(0.1+0.2)/2;
console.log(m);
// WARNING !!
// JavaScript uses the + operator for both addition and concatenation.
// Numbers are added. Strings are concatenated.
let s=X+Y;
console.log(s);
// A common mistake is to expect this result to be 102030:
let l="20";
let sum=X+Y+l;
console.log(sum);
// A common mistake is to expect this result to be 102030:
let lx="100";
let ly="10";
let ld=lx/ly;
console.log(ld);
console.log(lx*ly);
// NaN - Not a Number
// NaN is a JavaScript reserved word indicating that a number is not a legal number.
// Trying to do arithmetic with a non-numeric string will result in NaN (Not a Number):
let n=100/"apple";
console.log(n);
let ne=NaN;
console.log(typeof NAN);
// Infinity
// Infinity (or -Infinity) is the value JavaScript will return if you calculate a number outside the largest possible number.
let myno=2;
let text="";
while(myno !=Infinity)
{
myno=myno*myno;
text=text+myno;+"<br>";
}
console.log(text);
//zero also generate infinity
console.log(x/0);
let old=123;
let no= new Number(123);
console.log(typeof old,typeof no);
console.log(old==no);
console.log(old===no);