A better way to learn JavaScript - Built-in Objects
A better way to learn JavaScript - Built-in Objects
Save Yourself From Another 1000 Hours of Trial and Error Experiences!
About the Book
This book is a second in the series of 5 books on JavaScript.
In Book 1 we learned a lot about JavaScript. In Book 2, we "backfill" the wholes in our knowledge by having a detailed, in-depth look at all the built-in objects in JavaScript.
Understanding all the available methods and properties on built-in objects will do wonders for our confidence as JS developers.
Once you read this book, you can rest assured that whatever JS code comes your way, you'll know where it's coming from and how it works.
Books 1 and 2 are a solid foundation for working with some real-life code, with a lot of code snippets, and specific use cases. This is what Book 3 is about.
However, at the end of Book 2, we'll have a large section with all the code snippets extracted from both Books 1 and 2 (currently at about 90 code snippets, but as this book gets updated, by the end it should have at least 300 code snippets).
Both Books 1 and 2 aim to "draw the map of JavaScript", and are indeed a Better Way to Learn JS, because they are like a story about JavaScript that unwinds right before you.
Join me on this journey!
Bundles that include this book
Reader Testimonials
Peter Lin
https://twitter.com/PeterLin88
Hi Ajdin, I have been really enjoying learning from your 5 books of a-better-way-to-learn-javascript. It is really a better learning experience comparing to my reading of other JavaScript books or video courses. I have been very happy that I found and purchased them at leanpub.com. Excellent!! :)
Table of Contents
- Introduction
- Chapter 1: An overview of standard built-in objects
-
Chapter 2: The
Object
object-
The
Object
object -
The
Object
object’s methods and properties -
Static methods on the
Object
object -
Object
object’s static “create” methods -
Object
object’s static “read” methods -
Object
object’s static “update” methods -
Object
object’s static “freeze” methods -
Object
object’s instance properties and methods -
Object
object’s instance properties -
Object
object’s instance methods -
Object
object’s deprecated instance methods -
Object
object’s “checker” instance methods -
Object
object’s “conversion” instance methods
-
The
-
Chapter 3: The
Function
object-
The
Function
object -
Function.prototype.apply()
-
Whip up “Array.max” method with
Function.prototype.apply()
-
Function.prototype.call()
-
Function.prototype.bind()
- Why bind a function?
-
Use
bind()
to cement the context ofthis
-
Use
bind()
to partially apply a function -
Use
bind()
to pass context tosetTimeout()
-
Use
bind()
for invocation shortcuts -
Function.prototype.toString()
-
The
-
Chapter 4: The
Boolean
object-
The
Boolean
object -
The
Boolean
constructor and boolean primitives behave differently - Don’t convert a non-boolean using the constructor!
-
Built-in
Boolean
object’s instance methods
-
The
-
Chapter 5: The
Symbol
object-
The
Symbol
object - There’s no “shorthand syntax” for the symbol primitive
-
Symbol()
is a factory function -
Why is the
Symbol()
not a true constructor? -
Using a symbol’s optional
description
argument - How to get a symbol’s description?
- Why Symbols in ES6?
- How to add a symbol to an object literal?
- Getting the value of a symbol key from an object
-
Symbols are excluded from
for...in
loops - Pseudo-hidden properties on objects are made possible by symbols
- Why symbols in ES6, again?
- Why symbols are not truly hidden?
- Symbols are skipped in JSON conversions
- Symbols can be used to avoid code collisions
- Symbols can be used to fix ENUM lists
- Use symbols as metadata storage
- The global symbol registry
- The difference between local and global symbols
- Well-known symbols
- Conclusion
-
The
-
Chapter 6: Built-in collection objects:
Array
-
The
Array
object -
The
Array[@@species]
accessor -
The
Array.prototype[@@iterator]()
instance method -
The
Array.prototype[@@unscopables]
instance property -
The
Array.from()
static method -
The
Array.of()
static method -
The
Array.prototype.entries()
instance method -
The
Array.prototype.keys()
instance method -
The
Array.prototype.values()
instance method -
The
Array.prototype.findIndex()
instance method -
The
Array.prototype.lastIndexOf()
instance method -
The
Array.prototype.toLocaleString()
instance method -
The
Array.prototype.toString()
instance method -
The
Array.prototype.reduceRight()
instance method
-
The
-
Chapter 7: Built-in collection objects: typed array objects
- Why typed arrays in JS?
-
The immutability of
Blob
- Extracting Blob slices
-
Chapter 8: Built-in collection objects: maps, sets, weak maps, weak sets, and arguments
-
The
Map
object -
The
Set
object -
The
WeakMap
object -
The
WeakSet
object -
The
arguments
array-like object
-
The
-
Chapter 9: Error objects
- How to throw errors in JS?
- How to catch errors in JS gracefully?
- How to customize error messages in JS?
- What’s a stack trace?
- Strict mode and errors
- Browser sniffing and errors
- Errors and debugging
-
Chapter 10: Async-related and JSON-related objects
- An overview of built-in async-related objects, their properties, and methods
-
The
Promise()
constructor and thethen()
instance method - Wrapping methods into promise objects
-
Passing one more promise to the
resolveFn
-
The
Promise.all(iterable)
static method -
The
Promise.allSettled(iterable)
static method -
The
Promise.any(iterable)
static method -
The
Promise.race(iterable)
static method -
The
Promise.reject(reason)
static method -
The
Promise.resolve(value)
static method -
The
GeneratorFunction()
andAsyncFunction()
-
Using
Generator.prototype.next()
-
Using
Generator.prototype.return()
-
Using
Generator.prototype.throw()
-
The
JSON
object -
JSON.parse(text[, reviver])
-
JSON.stringify(value[, replacer[, space]])
-
The
ArrayBuffer
object -
The
SharedArrayBuffer
object -
The
Atomics
object -
The
DataView
object
-
Chapter 11: String, number, date, and internationalization objects
-
String
object’s built-in methods and properties - “CREATE” string methods
- “READ location” string methods
- “READ inclusion” string methods
- “READ string comparison” string methods
- “UPDATE join and split” string methods
- “UPDATE spacing” string methods
- “UPDATE letter casing” string methods
- DELETE
-
The
String.prototype
regex (pattern-matching) methods -
Number
object’s built-in methods and properties -
Date
object’s built-in methods and properties -
Intl
object’s built-in methods and properties
-
-
Chapter 12: Regular expressions in JavaScript
- What is a regular expression in JavaScript?
- Regular expression literal
- Check if an object is of RegExp type
- RegExp constructor function
- RegExp modifiers (aka “pattern flags”)
-
String.prototype.split()
withRegExp
-
String.prototype.replace()
withRegExp
-
String.prototype.search
withRegExp
-
String.prototype.match
withRegExp
-
String.prototype.matchAll()
andString.prototype.replaceAll()
- Character classes (aka character sets)
- Combining character classes
- Negating character classes
- Using the pipe for optional matching
- Metacharacters
- Regular expressions quantifiers
- RegExp assertions
-
Chapter 13: Reflection and proxy objects (metaprogramming in JS)
-
The
Reflect
object -
The
Proxy
object - Specifing a proxy handler object
- An example of each trap method
-
Back to the
Reflect
object - Proxy (trap) invariants
- Revocable proxies
- Building a proxy of a proxy
-
The
- Chapter 14: Web assembly objects
-
Chapter 15: Revision
- 1. Build a new object and specify its prototype
- 2. Copy enumerable own properties from one object to another
- 3. Copy enumerable own properties from multiple objects into a single object
- 4. Convert an array of arrays into an object
- 5. Covert an object into an array of arrays
- 6. Log out an object’s members as key-value pairs
- 7. Inspect an objects own property descriptor(s)
- 8. An alternative way of counting the number of members in an array
- 9. Count the number of members in an associative array
- 10. Find the number of own properties that an object has
- 11. Get values out of an associative array
- 12. On an object, add a named property with property descriptor editability
- 13. On an object, add multiple named properties with property descriptor editability
- 14. Prevent an object’s shallow properties from being deleted or changed (freeze an object)
- 15. Freeze an array
- 16. Prevent exensions of object’s properties but allow for deletions
- 17. Prevent extensions and deletions of an object’s properties
- 18. Define getters and setters on an object’s property
- 19. Define getters and setters directly on an object literal
- 20. Inspect getters and setters on an object’s specific property
- 21. Check if an object has an own property and return a boolean of the result
- 22. Check if an object’s own property’s property is enumerable
- 23. Check if an object is a prototype of another object
- 24. Call a method to check the number of arguments a function expects
-
25. Log out all the arguments passed to a function call using the
arguments
array-like object -
26. Apply an object as the
this
value of another object’s method -
27. Pass arguments to a function using the
apply()
method without specifying the this argument - 28. Concatenate any number of arguments using the built-in “arguments” array-like variable
- 29. Sum up any number of arguments using the built-in “arguments” array-like variable
-
30. Concatenate the values of all the object’s properties, using another object’s
joiner
function -
31. Borrow
Math.max()
static method and apply it on an array of numbers to get the highest number -
32. Borrow
Math.min()
static method and apply it on an array of numbers to get the lowest number - 33. Use apply to monkey patch (extend) a built-in object as a polyfill on an older browser
-
34. Borrow a method from one object to another object using
call()
without arguments -
35. Borrow a method from one object to another object using
call()
with arguments -
36. Use
apply()
instead ofcall()
in a given code snippet -
37. Prove that every function call is calling the
call()
method in the background -
38. Chain constructors with the
call()
method -
39. Fix the problem of keeping the context of
this
in a nested function - 40. Why bind a function?
-
41. Use
bind()
to cement the context of this -
42. Use
bind()
to partially apply a function -
43. Use
bind()
to pass context tosetTimeout()
-
44. Use
bind()
to make invocation shortcut onArray.prototype.slice()
- 45. Set a symbol as an object’s key
- 46. Add a symbol to an object literal
- 47. Prove that each symbol is unique
-
48. Check if a variable is of type
symbol
- 49. Log out a symbol’s description
- 50. Why were symbols added to ES6?
- 51. Get the value of a symbol key from an object
-
52. Prove that symbols are excluded from
for..in
loops - 53. Add a symbol to an object without storing the symbol in a variable beforehand
- 54. Prove that symbols are skipped in JSON conversion
- 55. What will happen if we try to reassign an existing symbol property in an object
- 56. Use a symbol to fix an ENUM list
- 57. Show how to use a symbol as a metadata storage
-
58. Show a use case for the
Array[@@species]
accessor -
59. Reimplement a “regular” iterator with
Array.prototype[@@iterator]()
- 60. Build an iterator that iterates over every even member of an array
- 61. Build an iterator that iterates over every odd member of an array
-
60. Convert a
Set
to anArray
-
61. Use a mapping function with
Array.from()
-
62. Convert a
string
to anArray
withArray.of()
-
63. Iterate over an array with
Array.prototype.entries
-
64. Iterate over an array and break out of a loop based on a condition, using
Array.prototype.entries
-
65. Split an array into a series of arrays using
Array.prototype.entries
-
66. Split an array into a series of objects using
Array.prototype.entries
-
67. Push array keys into a separate array using
Array.prototype.keys
-
68. Print array values using
Array.prototype.values
-
69. Find index of a matching member of array or return -1 with
Array.prototype.findIndex
-
70. Search for a match from the end of array with
Array.prototype.lastIndexOf
-
71. Localize a decimal number as price with
Array.prototype.toLocaleString
-
72. Concatenate all args using
Array.prototype.reduce
-
73. Concatenate all args using
Array.prototype.reduceRight
- 74. How to throw errors in JS?
- 75. How to catch errors in JS gracefully?
- 76. How to customize error messages in JS?
-
77. Show that the
Promise()
constructor must take a callback function -
78. Why no error is thrown when we call
then()
on a promise, without passing any functions tothen()
- 79. Build a promise that randomly fetches data from coindesk or throws an error, and catches it
- 80. Display a message at the end of a promise regardless of whether it succeeds or fails
-
81. Deal with potential errors by passing the second argument to the
then()
call in a promise - 82. “Promisify” a method that does not usually return a promise object
- 83. Log out a sentence from inside a promise
- 84. Send a notification of a promise successfully fulfilled
-
85. Give an example of using
Promise.reject()
-
86. Give an example of using
Promise.resolve()
-
87. Return the
GeneratorFunction()
constructor -
88. Return the
AsyncFunction()
constructor -
89. Iterate values using
Generator.prototype.next()
-
90. Iterate an array using
Generator.prototype.next()
- 91. Send values to the generator
-
92. Show that the
Generator.prototype.return()
finishes the generator
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them