Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
39 views

JavaScript Numbers

JavaScript numbers can be written with or without decimals. Integers are accurate up to 15 digits while adding a number to a string results in string concatenation. NaN is returned if a non-numeric string is divided by a number, indicating the value is not a legal number. Infinity is returned for values outside the largest possible number range, such as division by zero. Numbers can also be written in hexadecimal format by prefixing with 0x.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

JavaScript Numbers

JavaScript numbers can be written with or without decimals. Integers are accurate up to 15 digits while adding a number to a string results in string concatenation. NaN is returned if a non-numeric string is divided by a number, indicating the value is not a legal number. Infinity is returned for values outside the largest possible number range, such as division by zero. Numbers can also be written in hexadecimal format by prefixing with 0x.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 48

JAVASCRIPT

NUMBERS
NUMBERS

It can be written with or


without decimals

A number with decimals


A number without decimals
EX
A
MP
LE
S

3
INTEGER PRECISION

╸ Integers (numbers without a


period or exponent notation)
are accurate up to 15 digits.

4
EX
A
MP
LE
S

5
FLOATING PRECISION

A complex idea can be


conveyed with just a
single still image, namely
making it possible to
absorb large amounts of
data quickly.
6
EX
A
MP
LE
S

7
ADDING NUMBERS
AND STRINGS

8
ADDING NUMBERS AND STRINGS
If a number is added to a number the
result will be number.

If a number is added to a string the


result will be a string concatenation.

9
EX
A
MP
LE
S

A number added to a number.

10
EX
A
MP
LE
S

A number added to a string.


11
Quick Question

let x = 8;
let y = 5;
console.log(”The result will be: ” + x +
y);
Quick Question

// ”There result will be: 85 ”;


Quick Question

let x = 5;
let y = 5;
console.log( x + y + ” is equal to 10”);
Quick Question

// ”10 is equal to 10”;


ADDING NUMBERS AND
STRINGS

JavaScript Interpreter works


from left to right;

16
ADDING NUMBERS AND
STRINGS

You can multiply, divide and


subtract a number in a string.

17
EX
A
MP
LE
2

18
EX
A
MP
LE
2

19
EXAM
PLE3

20
NOT A NUMBER

21
Not A Number
╸ NaN
╸ a JavaScript reserved word
indicating that a number is not
a legal number.
╸ Returns a number
Note: Don’t use NaN in a mathematical
operation.

22
NOT A NUMBER

23
NOT A NUMBER
╸ If a number is divided to a non-
numeric string the result will be a
NaN .
╸ If a number is divided by a numeric
string the result will be a number.

Note: use the global JavaScript function


isNaN() to find if a value is not a number.
24
EX
A
MP
LE
S

25
EX
A
MP
LE
S

26
EX
A
MP
LE
S

27
INFINITY / -
INFINITY

28
INFINITY OR -INFINITY

╸ Return if a number
outside has been
calculate is largest
possible number.

29
EX
A
MP
LE
S

30
EX
A
MP
LE
S

31
INFINITY OR -INFINITY

╸ Division by 0 also
generates Infinity

32
INFINITY OR -INFINITY

╸ Return as a Number

33
HEXADECIM
AL
HEXADECIMAL
╸ JavaScript interprets numeric constants
as hexadecimal if they are preceded by
0x.

35
EX
A
MP
LE
S

36
NOTE:
╸ Never write a number with a leading
zero (like 07).
Some JavaScript versions interpret
numbers as octal if they are written
with a leading zero.

37
EXAMPLE:

38
JAVASCRIPT
NUMBERS AS
OBJECTS
JAVASCRIPT NUMBERS AS OBJECTS

╸ Numbers are primitive values created


from literals.

╸ But numbers can also be defined as


objects with the keyword new.

40
NOTE:

╸ Do not create Number objects.


╸ The new keyword complicates the code
and slows down execution speed.
╸ Number Objects can produce
unexpected results:

41
COMPARISON
OPERATOR.
EQUAL

╸ Symbol double ==

43
NOT EQUAL

╸ Symbol double ===

44
45
╸THANK YOU
EVERY // ONE

46
NEXT……..
JAVASCRIPT
BIGINT

You might also like