Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Object-Oriented JavaScript
  • Table Of Contents Toc
  • Feedback & Rating feedback
Object-Oriented JavaScript

Object-Oriented JavaScript

4.5 (48)
close
close
Object-Oriented JavaScript

Object-Oriented JavaScript

4.5 (48)

Overview of this book

Table of Contents (18 chapters)
close
close
Object-Oriented JavaScript
Credits
About the Author
About the Reviewers
Preface
2
Built-in Functions
4
Regular Expressions
5
Index

Number


Creates number objects:

>>> var n = new Number(101);
>>> typeof n

"object"

>>> n.valueOf();

101

Number objects are not primitive objects, but if you use a number method on a primitive number, the primitive will be converted to a Number object behind the scenes and the code will work.

>>> var n = 123;
>>> typeof n;

"number"

>>> n.toString()

"123"

Members of the Number Constructor

Property/Method

Description

Number.MAX_VALUE

A constant property (cannot be changed) that contains the maximum allowed number.

>>> Number.MAX_VALUE

1.7976931348623157e+308

>>> Number.MAX_VALUE = 101;

Number.MAX_VALUE is read-only

Number.MIN_VALUE

The smallest number you can work with in JavaScript.

>>> Number.MIN_VALUE

5e-324

Number.NaN

Contains the Not A Number number.

>>> Number.NaN 

NaN

NaN is not equal to anything including itself.

>>> Number.NaN === NaN 

false

Number.NaN is more reliable than simply using NaN, because the latter can be overwritten by mistake.

>>> NaN = 1; // don't do this!

1

>>> NaN 

1

>>> Number.NaN 

NaN

Number.POSITIVE_INFINITY

Contains the Infinity number. This is more reliable than the global Infinity value (property of the global object) because it is read-only.

Number.NEGATIVE_INFINITY

Has the value -Infinity. See above.

Members of the Number Objects

Property/Method

Description

toFixed(fractionDigits)

Fixed-point representation of a number object as a string. Rounds the returned value.

>>> var n = new Number(Math.PI);
>>> n.valueOf();

3.141592653589793

>>> n.toFixed(3)

"3.142"

toExponential(fractionDigits)

Exponential notation of a number object as a string. Rounds the returned value.

>>> var n = new Number(56789);
>>> n.toExponential(2)

"5.68e+4"

toPrecision(precision)

String representation of a number object, either exponential or fixed-point, depending on the number object.

>>> var n = new Number(56789);
>>> n.toPrecision(2)

"5.7e+4"

>>> n.toPrecision(5)

"56789"

>>> n.toPrecision(4)

"5.679e+4"

>>> var n = new Number(Math.PI);
>>> n.toPrecision(4)

"3.142"

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Object-Oriented JavaScript
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon