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.
See full terms
Do Well. Do Good.
Authors have earned$11,826,004writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
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
Top Books
Stratospheric
Tom Hombergs, Björn Wilmsmann, and Philip RiecksFrom Zero to Production with Spring Boot and AWS. All you need to know to get a Spring Boot application into production with AWS. No previous AWS knowledge required.
Go to stratospheric.dev for a tour of the contents.
Advanced Web Application Architecture
Matthias NobackThe missing manual for making your web applications future-proof
node-opcua by example
Etienne RossignonGet the best out of node-opcua through a set of documented examples by the author himself that will allow you to create stunning OPCUA Servers or Clients.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Introduction to Data Science
Rafael A IrizarryThe demand for skilled data science practitioners in industry, academia, and government is rapidly growing. This book introduces concepts from probability, statistical inference, linear regression and machine learning and R programming skills. Throughout the book we demonstrate how these can help you tackle real-world data analysis challenges.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Aprendiendo Git
Miguel Angel Durán GarcíaGit no es complicado... ¡Si lo entiendes! 😜
¿Sientes que sabes usarlo porque has memorizado todos los comandos que necesitas? ¡Pero no entiendes qué hace cada cosa y por qué! Así es normal que, cuando exista un problema, te cueste resolverlo.
¡Con este libro vas a entender de una vez por todas todo lo que es Git y cómo sacarle provecho!
Discrete Mathematics for Computer Science
Alexander Shen, Alexander S. Kulikov, Vladimir Podolskii, and Alexander GolovnevThis book supplements the DM for CS Specialization at Coursera and contains many interactive puzzles, autograded quizzes, and code snippets. They are intended to help you to discover important ideas in discrete mathematics on your own. By purchasing the book, you will get all updates of the book free of charge when they are released.
Top Bundles
- #1
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #2
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #6
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #10
Learn Git, Bash, and Terraform the Hard Way
3 Books
Learn Git, Bash and Terraform using the Hard Way method.These technologies are essential tools in the DevOps armoury. These books walk you through their features and subtleties in a simple, gradual way that reinforces learning rather than baffling you with theory.