Types & Grammar
Kyle Simpson
You Don’t Know JS: Types & Grammar
by Kyle Simpson
Copyright © 2015 Getify Solutions, Inc. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
Editors: Simon St. Laurent and Brian MacDonald
Production Editor: Kristen Brown
Copyeditor: Christina Edwards
Proofreader: Charles Roumeliotis
Interior Designer: David Futato
Cover Designer: Ellie Volckhausen
February 2015: First Edition
Revision History for the First Edition
2015-01-23: First Release
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author(s) disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-491-90419-0
[LSI]
Foreword
Preface
Mission
Review
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
1. Types
A Type by Any Other Name…
Built-in Types
Values as Types
undefined Versus “undeclared”
typeof Undeclared
Review
2. Values
Arrays
Array-Likes
Strings
Numbers
Numeric Syntax
Small Decimal Values
Safe Integer Ranges
Testing for Integers
32-Bit (Signed) Integers
Special Values
The Nonvalue Values
Undefined
Special Numbers
Special Equality
Value Versus Reference
Review
3. Natives
Internal [[Class]]
Boxing Wrappers
Object Wrapper Gotchas
Unboxing
Natives as Constructors
Array(. .
)Object(. . ), Function(. . ), and RegExp(. . )
Date(. . ) and Error(. . )
Symbol(. . )
Native Prototypes
Review
4. Coercion
Converting Values
Abstract Value Operations
ToString
ToNumber
ToBoolean
Explicit Coercion
Explicitly: Strings <--> Numbers
Explicitly: Parsing Numeric Strings
Explicitly: * --> Boolean
Implicit Coercion
Simplifying Implicitly
Implicitly: Strings <--> Numbers
Implicitly: Booleans --> Numbers
Implicitly: * --> Boolean
Operators || and &&