Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Object-Oriented JavaScript

You're reading from   Object-Oriented JavaScript Learn everything you need to know about object-oriented JavaScript (OOJS)

Arrow left icon
Product type Paperback
Published in Jan 2017
Publisher Packt
ISBN-13 9781785880568
Length 550 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Ved Antani Ved Antani
Author Profile Icon Ved Antani
Ved Antani
Stoyan STEFANOV Stoyan STEFANOV
Author Profile Icon Stoyan STEFANOV
Stoyan STEFANOV
Arrow right icon
View More author details
Toc

Table of Contents (25) Chapters Close

Object-Oriented JavaScript - Third Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Object-Oriented JavaScript FREE CHAPTER 2. Primitive Data Types, Arrays, Loops, and Conditions 3. Functions 4. Objects 5. ES6 Iterators and Generators 6. Prototype 7. Inheritance 8. Classes and Modules 9. Promises and Proxies 10. The Browser Environment 11. Coding and Design Patterns 12. Testing and Debugging 13. Reactive Programming and React Reserved Words Built-in Functions
Built-in Objects Regular Expressions
Answers to Exercise Questions

Appendix B. Built-in Functions

This appendix contains a list of the built-in functions (methods of the global object), discussed in Chapter 3, Functions:

Function

Description

parseInt()

Takes two parameters: an input object and radix; then tries to return an integer representation of the input. Doesn't handle exponents in the input. The default radix is 10 (a decimal number). Returns NaN on failure. Omitting the radix may lead to unexpected results (for example for inputs such as 08), so it's best to always specify it:

    > parseInt('10e+3');   
    10   
    > parseInt('FF');   
    NaN   
    > parseInt('FF', 16);   
    255   

parseFloat()

Takes a parameter and tries to return a floating-point number representation of it. Understands exponents in the input:

    > parseFloat('10e+3');   
    10000   
    > parseFloat('123.456test');   
    123.456   

isNaN()

Abbreviated from "Is Not a Number". Accepts a parameter and returns true if the parameter is not a valid number, false otherwise. Attempts to convert the input to a number first:

    > isNaN(NaN);   
    true   
    > isNaN(123);   
    false   
    > isNaN(parseInt('FF'));   
    true   
    > isNaN(parseInt('FF', 16));   
    false   

isFinite()

Returns true if the input is a number (or can be converted to a number), but if it is not a number Infinity or - Infinity. Returns false for infinity or non-numeric values:

    > isFinite(1e+1000);   
    false   
    > isFinite(-Infinity);   
    false   
    > isFinite("123");   
    true   

encodeURIComponent()

Converts the input into a URL-encoded string. For more details on how URL encoding works, refer to the Wikipedia article at http://en.wikipedia.org/wiki/Url_encode:

    > encodeURIComponent   
    ('http://phpied.com/');   
    "http%3A%2F%2Fphpied.com%2F"   
    > encodeURIComponent   
    ('some script?key=v@lue');   
    "some%20script%3Fkey%3Dv%40lue"   

decodeURIComponent()

Takes an URL-encoded string and decodes it:

    > decodeURIComponent('%20%40%20');   
    " @ "   

encodeURI()

URL-encodes the input, but assumes a full URL is given, so returns a valid URL by not encoding the protocol (for example, http://) and hostname (for example, www.phpied.com):

    > encodeURI('http://phpied.com/');   
    "http://phpied.com/"   
    > encodeURI('some   script?key=v@lue');   
    "some%20script?key=v@lue"   

decodeURI()

Opposite of encodeURI():

    > decodeURI("some%20script?key=v@lue");   
    "some script?key=v@lue"   

eval()

Accepts a string of JavaScript code and executes it. Returns the result of the last expression in the input string.

To be avoided where possible:

    > eval('1 + 2');   
    3   
    > eval('parseInt("123")');   
    123   
    > eval('new Array(1, 2, 3)');   
    [1, 2, 3]   
    > eval('new Array(1, 2, 3); 1 +   2;');   
    3   

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images