A Better Way To Learn JavaScript
A Better Way To Learn JavaScript
Save Yourself From 1000 Hours of Trial and Error Experiences!
About the Book
This book is based on a tried and tested learning methodology.
This learning methodology will give you the best possible results in the shortest amount of time!
Along the way, you'll learn how to build truly useful apps in JavaScript, which will speed up your workflow and help you with your daily tasks.
Bundles that include this book
Table of Contents
-
Introduction
- You can’t make everyone happy
- This one goes out to the happy ones
- How is this book organized?
- The methodology: Bloom’s taxonomy
- 1. “Map of the JavaScript land”
- 2. Types of tutorials
- 3. Focusing on “knowledge transfer”, not “feature-listing”
- 4. Most of these books are either too theoretical or too practical
- What We’re Building
- Accompanying website
-
Chapter 1: The Absolute Basics
- How a website works and where does JavaScript fit in
- A Function is A Machine
- Generalizing Functions in JavaScript
- Anonymous functions
- Conclusions
- What’s next?
- A quick note about var, let and const
-
Chapter 2: The Quick Prototype App
- Before We Build the App
- Building the Quick Prototyper App
- Using Github to Share our code
- Updating Our Web Page Dynamically
- Reinforcing Our Learning With Devtools Snippets
- Start Building the Quick Prototyper snippet
- Checking for Equality and Running our Code Conditionally
- Adding a Second Component to Quick Prototyper
- Passing Custom Arguments to Our Function Calls Based on User Input
- Prompting For Multiple Components At a Time
- Conclusion
-
Chapter 3: Understanding Events in JavaScript
- What are Events in JavaScript
- Inline Event Handlers Using HTML Attributes
- How JavaScript Deals with Events
- Stopping Event Propagation
- Add an Event Handler to our Page Dynamically
- The Event Object
-
Chapter 4: Improving the UX on Quick Prototyper
- Adding badges to the list of components
- Adding Buttons To our App
- Adding the Navbar to our QuickPrototyper
- List of Updates Made to QuickPrototyperV10
-
Chapter 5: Introducing jQuery
- Understanding the basics of jQuery
-
Adding the
textToEdit
andpopUpEditor
divs -
Styling the
popUpEditor
-
Chapter 6: The Anatomy of functions in ES6
- Comparing ES5 and ES6 functions in JavaScript
- Function definitions with a single parameter
- Function definitions with no parameters
- Converting ES5 to ES6 functions (and vice-versa)
-
Chapter 7: Learning JavaScript basics by coding tiny apps
- What’s fiction writing have to do with coding?
- Version one of our Learning JavaScript Project
- Version two of our Learning JavaScript Project
- Why is this important?
- Learning JS basics by coding tiny apps: Let’s build a choices game
- Escaping the console and the prompt function
- Building the “JS Money” game
- Using a ternary expression in our game
- Add CSS classes using JavaScript
- Conclusion
-
Chapter 8: Data Types and Constructors
- Objects VS non-objects
-
Finding the type of primitives using the
typeof
operator - The number type
- The null type
- The undefined type
- The boolean type
-
The
bigint
type - The symbol type
- Understanding primitive data types in JavaScript
- Primitive types cannot be mutated
- The object type
- Wrapper objects on primitives in JavaScript
- Type constructors in JavaScript: The good, the bad, and the ugly
- What does the “new” operator do?
- Some built-in objects don’t need a constructor - because they’re static objects
- Building objects with user-defined constructor functions
- Rule of thumb: use literals rather than object function constructors
- Typecasting with type constructors
- Forgetting the new keyword pollutes global scope!
- Comparing primitive values in JavaScript
- Comparing objects in JavaScript
- Primitives are passed by value
- Objects are passed by reference
- Truthy and falsy values and coercion in JavaScript
- Conclusion
-
Chapter 9: JavaScript and the Browser
- “The states of matter” of a web page
-
A sneak preview:
document.write
- What is the DOM?
- Is the DOM a part of JavaScript?
- Where does JavaScript live?
- Browser and Web APIs
- JavaScript Engines and Browser Engines
- How a JavaScript Engine Works
- The Memory Heap
- The Call Stack
- Stack Overflow
- Recursion in JavaScript
- The memory heap and JavaScript variables
- Variable hoisting VS function hoisting
- Using the debugger to understand hoisting
- The global object
- The call stack, the global object, and the keyword “this”
- Functions, call stack, and execution contexts
- Why do we need the scope chain?
- Sibling functions don’t share a scope chain
- Back to the this keyword
- Conclusion
-
Chapter 10: JavaScript is Synchronous, Browser is Asynchronous
- JavaScript is Single-Threaded and Synchronous
- Synchronous JavaScript in an Asynchronous Browser
- Conclusion
-
Chapter 11: Basic JavaScript Caveats
- Higher-order functions
- Revisiting scope: global, function, and block scope
- Closures (the products of higher-order functions)
- Lexical Scope
- Variables: var VS let and const
- Operator precedence and associativity
- Default parameters in functions
-
Using
call()
andapply()
-
Implicit and explicit context of
this
-
Using
bind()
- Working with local storage
- Method chaining
- JavaScript loading in an HTML page
- Nullish coalescing operator
- Optional chaining operator
-
Chapter 12: The Anatomy of a JavaScript Function: all the different ways of defining functions in JS
- 1. Function declarations
- 1a. Conditionals and function declarations
- 2. Function expressions
- 2a. Function expressions as IIFEs
- 2b. Function expressions as object methods
- 2c. Function expressions as shorthand methods in ES6 object literals
- 2d. Function expressions as shorthand methods with the computed properties syntax
- 2e. Function expressions as callbacks
- 2f. Function expressions as arrow functions
- 2f. How does the JavaScript engine load functions into the execution context?
- 3. Function constructors
- 4. Generator functions
- 5. Async / await functions
- Conclusion
-
Chapter 13: Understanding arguments and the spread operator
- How many arguments does a function expect?
-
The
arguments
variable - Can we use the arguments variable with arrow functions?
- How does the spread operator work in arrow functions?
-
Understanding the
arguments
local variable in depth
-
Chapter 14: JavaScript Arrays in Depth
-
Using the
delete
method on an array member - Does a value exist in an array?
-
Use
Array.length
to find the last member of array - Use Array.length to quickly trim an array
-
Manipulating arrays with
pop
-
Manipulating arrays with
push
-
Manipulating arrays with
shift
-
Manipulating arrays with
unshift
-
Manipulating arrays with
Array.slice
andArray.splice
- Destructuring Arrays
- Concat two arrays together
- Convert an array to a string
- Flipping the order of items in an array
-
Sorting arrays with
Array.sort
- Exercise: Sort a todo list
- Additional Exercise: Reverse the order of array
- Looping over arrays
-
2. Using the “optimized”
for
loop -
3. Looping over a JS array with
for-of
-
4. Don’t loop over a JS array with
for-in
- 5. Looping over a JS array with the while loop
-
6. Looping over a JS array with the
do while
loop - Functional approach to looping over arrays in JS
-
7. Looping over arrays in JS with
forEach
-
8. Looping over arrays in JS with
Array.prototype.filter
-
Using
Array.prototype.filter
followed byArray.prototype.forEach
-
10. Using
Array.prototype.map
-
11. Using
Array.prototype.reduce
-
12. Using
Array.prototype.some
-
13.
Array.prototype.every
-
14. Using
Array.prototype.find
-
15. Using
Array.prototype.sort
- Looping over arrays: Conclusion
-
Using the
-
Chapter 15: Sets and Maps in JavaScript
- A Set is a Collection of Unique Members
- Convert a set to an array
- Convert an array to a set
- Remove duplicates from an array using a set
- Just for fun (re-duplicate an array)
- Does a value exist in a set?
- Sets don’t consider objects the same even if they hold the same values
- Check the length of a set
- Using two sets to find the items that exist in both
- Deleting set members
- Comparing sets and weak sets
- Practical Uses of Weak Sets in JavaScript
- Looping over sets and weak sets
- Working with maps in JavaScript
- A map is like a “countable” object (i.e. a dictionary)
- Using the map data structure in JS
- Populating a map data structure in JS
- Retrieving all the key-value pairs from a map
- Passing more than one key-value pairs to a new map
- What is the size of a specific map?
- Adding key-value pairs to existing maps
- Does a key exist in a map?
- Returning a value from a map key in JS
- Deleting key-value pairs from maps in JS
- Clearing a map of all key-value pairs
- Convert a map to an array
- Convert a map to an object
- Comparing maps and objects
- Weak maps in JS
- Weak maps and weak sets help with memory use
- Looping over maps
- Looping over a map with a forEach
-
Chapter 16: JavaScript Objects in Depth
- What are objects in JS?
- Object literals and object accessors
- Nesting objects in other objects in JavaScript
- Working with object properties
- Running CRUD operations on object properties in JavaScript using brackets notation
- The difference between the dot notation and the brackets notation for object access
- Using ternary expressions to determine the value of a property
- Evaluating expressions inside objects using the brackets notation
- Listing out object properties
- JavaScript objects are “pass-by-reference”
- Passing objects to functions
- Accessing object properties from object methods
-
Using
Object.create
method - Built-in objects in JavaScript
- The String object
- The RegExp object
- Using RegExp in JavaScript
- Date object
- JSON (JavaScript Object Notation)
- Math object
- Working with property descriptors
- Working with the writable property descriptor
- Working with the enumerable property descriptor
- Working with the configurable property descriptor
- Working with getters and setters
- Destructuring objects in JavaScript
-
Chapter 17: Working with Objects, Arrays, and JSON
- Working With JSON Received From The Web
-
Chapter 18: Functional programming in JavaScript
- What is it?
- FP VS OOP
- Declerative and imperative paradigms
- Side effects and pure functions
- Immutability
- Function Composition, Partial Application, and Currying
-
Chapter 19: Object-Oriented Programming in JavaScript
- What is OOP?
- Polymorphism
- Encapsulation
- Inheritance
- Classes
- Objects Store Both Functions And Data
- Building multiple objects
- Linking Objects with Object.create
- My name is Proto, Dunder Proto
- In JavaScript, functions are objects
-
The Proper Way to Use
prototype
Is With A Constructor Function - Getting an Object’s Prototype
- Why JavaScript is not class-based “under the hood”
- Constructor functions and object-oriented JavaScript
-
Arrow functions fix the
this
reference in inner functions -
Extending Array.prototype with
defineProperty
- Using classes in JavaScript
- Why use classes over prototypes?
-
Object
is a global constructor function - Three ways to check for prototype
- Practice makes perfect: the prototype chain
-
The
instanceof
operator and object-oriented JavaScript -
Function
,Object
andinstanceof
- The Constructor Property
-
Chaining constructors for an object with
call
- Practice makes perfect: let’s build a prototype chain!
-
Using
Object.create
to add prototypes for objects - Static Methods
- Public and Private Methods
-
Inheritance using
extends
andsuper
- Monkey-patching
- By-passing inheritance using mixins
- Shallow copy and deep copy
-
Chapter 20: Errors, debugging, and strict mode
- Throwing errors in JavaScript
-
The
try...catch...finally
statement - Throwing the error
- Catching the error
- As soon as an error is thrown, the try block is DONE
-
The
finally
statement - Catching all types of errors
- Custom error messages
- Stack Trace
-
Using
console.trace()
- Traces and function names
-
Debugging with
console.trace()
- Stack tracing Error constructors
- Strict mode
- 1. All variables must be declared
- 2. Non-writable global variables cannot be used as a variable names
- 3. Duplicate parameters are not allowed
- 4. Functions must be declared in the global scope or directly inside a function
-
5. The
with
statement is forbidden - 6. Decimals with leading zeros are not allowed
- 7. Not allowed to set or delete immutable properties
- BROWSER SNIFFING
- FEATURE SNIFFING
- DEBUGGING JAVASCRIPT
- Debugging with console and alert
- The quickest way to run the built-in devtools debugger
- Pausing on exceptions
- What is a breakpoint?
- Local scope, global scope, and closures in the debugger
-
Using the
debugger
keyword to programmatically set a breakpoint - Editing breakpoints (watching expressions)
- Working with different types of breakpoints
- Step over, step into, step out, and step
- Debugging with the Step into next function call button
- The Deactivate / Activate breakpoints button
- Inspecting the call stack
- Debugging with Chrome devtools Performance panel
- Blackboxing scripts
- JavaScript sourcemaps
- AVOIDING THE NEED TO DEBUG
- LINTERS AND CODE EDITORS
- Installing ESLint with npm
-
Chapter 21: Modular JavaScript
- What problems does modular JavaScript code solve
- How to install Node and npm on our machine?
- Adding a new project with npm
- Adding actual code to our npm project
- Collaborating in a team using npm
- Using npm scripts and task runners
- Modular JavaScript
-
We can’t use
require
in the browser - What is a module bundler?
- Working with ES6 modules (ESM syntax)
- Working with ES6 modules in the browser
- Running an Express server
- How does webpack work?
- Adding webpack to our JavaScript programs
-
Understanding the structure of the
node_modules
folder - Working with npm scripts
- Running files with Node.js using npm scripts
- Running webpack on our project’s files
- Running webpack on vanilla JavaScript modules
- Compiling JavaScript modules to a custom output with webpack
- Specifying custom entry file in the webpack configuration
- Building HTML files with webpack
-
The
module
object -
Exporting various values with
module.exports
- How to set up webpack with html files
- Conclusion
-
Chapter 22: JavaScript Object Notation (JSON)
- What is JSON
- Why is JSON so popular?
- What does valid JSON look like
- Using JSON tools for increased productivity
- Looping over JSON objects
- Making AJAX requests to get JSON data from the web
- An alternative solution to printing JSON data to screen
- Transforming objects to arrays to deal with JSON data, explanation
- Making AJAX requests to get JSON data from our own computer
- Printing data to screen using nested for loops
-
Running JSON.parse on
undefined
vs running it onnull
- Conclusion
-
Chapter 23: Asynchronous JavaScript
- What are blocking operations?
- The XMLHttpRequest constructor
- The anatomy of an XHR request
- What are callbacks?
- Let’s build callbacks from ground up
- Functions are first-class citizens
- Passing strings to functions
- Passing function invocations to functions
- Higher-order functions take or return other functions
- Passing named function declarations to other functions
- Passing anonymous functions to higher order functions
- Understanding callbacks in general
- Callbacks are everywhere
- Running a callback function when a button is clicked
- Using callbacks to run XHR requests
- Asynchronous XHR inside a callback function
- The biggest difference between regular functions and asynchronous (callback) functions
- The problem with callbacks
- Callbacks and the inversion of control
- Callback hell aka The Pyramid of Doom
- A more realistic example of callback hell
- Intermission: where we’re at
- Dealing with errors in callbacks
- Dealing with callback hell
- Promises
-
Working with promises using the
fetch()
method - Understanding promises
-
What is the contents of
[[]]
? -
Dealing with rejected promises using the
catch()
method -
Error handling in promises with
catch()
andfinally()
-
Dealing with rejected promises by passing the second argument to the
then()
method - How do the functions deferred by a promise get back onto the call stack?
- A few important conclusions regarding promises
- Working with Promise.all
- Iterators and Generators
- Iterators perform work on streams of data
- The iteration protocol
- Generators
- An instance of GeneratorFunction is an iterable object!
-
Returning values dynamically with
yield
- Combining generators with promises
- Async/Await
- Observables
- Revisiting the iterator patern
- The observer pattern
- Observables in vanilla JS
- Revising observables
- Subscribing to an observable data stream with RxJS
- Conclusion: The JavaScript Learning Fractal
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,592,641writing, 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), EPUB (for phones and tablets) and MOBI (for 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
SignalR on .NET 6 - the Complete Guide
Fiodar SazanavetsLearn everything there is to learn about SignalR and how to integrate it with the latest .NET 6 and C# 10 features. Learn how to connect any type of client to SignalR, including plain WebSocket client. Learn how to build interactive applications that can communicate with each other in real time without making excessive calls.
The easiest way to learn design patterns
Fiodar SazanavetsLearn design patterns in the easiest way possible. You will no longer have to brute-force your way through each one of them while trying to figure out how it works. The book provides a unique methodology that will make your understanding of design patterns stick. It can also be used as a reference book where you can find design patterns in seconds.
C++20 - The Complete Guide
Nicolai M. JosuttisAll the new language and library features of C++20 (for those who know previous 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:
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
Functional event-driven architecture: Powered by Scala 3
Gabriel VolpeExplore the event-driven architecture (EDA) in a purely functional way, mainly powered by Fs2 streams in Scala 3!
Leverage your functional programming skills by designing and writing stateless microservices that scale, powered by stateful message brokers.
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.
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.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
CCIE Service Provider Version 4 Written and Lab Exam Comprehensive Guide
Nicholas RussoThe service provider landscape has changed rapidly over the past several years. Networking vendors are continuing to propose new standards, techniques, and procedures for overcoming new challenges while concurrently reducing costs and delivering new services. Cisco has recently updated the CCIE Service Provider track to reflect these changes; this book represents the author's personal journey in achieving that certification.
Cronache di Domain-Driven Design
Francesco Strazzullo, Matteo Baglini, Gianluca Padovani, Emanuele DelBono, Marco Consolaro, Alessandro Colla, Uberto Barbini, Alberto Acerbis, Julie Camosseto, DDD Open, and Alberto BrandoliniCronache di Domain-Driven Design: un libro corale in italiano fatto di storie indipendenti tra loro, che sono il risultato dell’applicazione di Domain-Driven Design su progetti reali.
Top Bundles
- #1
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!? - #2
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
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... - #3
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
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... - #6
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... - #7
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also... - #10
Growing Agile: The Complete Coach's Guide
7 Books
Growing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity...