Table of Contents....4
About the Author....12
About the Technical Reviewer....13
Introduction....14
Chapter 1: Introduction to JavaScript....15
JavaScript Fundamentals....16
JavaScript’s Type Classification....17
What Is JavaScript Used For?....18
Writing JavaScript....19
Setting Up a Code Editor....21
Starting Up Our Code....22
How to Get Started with Writing Back-End JavaScript....23
Creating Node.js JavaScript Projects....25
JavaScript Support....26
Summary....28
Chapter 2: Code Structure and Logical Statements....29
Getting Started....29
Common Code Conventions....31
Semicolons....31
Spacing....32
Variable and Function Naming....33
JavaScript Variables....33
Setting Variables with let....34
Block Scoping with Variables....35
Setting Variables with var....36
Setting Variables with const....37
Mutation of const Variables....38
Defining Variables Without Values....39
Assignment Operators....40
Variable Concatenation....41
Template Literals....42
JavaScript Comments....43
Logical Statements....44
If…else Statements....44
Switch Statements....47
Defaulting to a Clause with Switch Statements....49
Equality with Switch Statements....49
Block Scoping with Logical Statements....50
Conditional Operator in Variables....52
Logical Statement Comparison Operators....52
Logical Statement Logical Operators....55
Summary....56
Chapter 3: Introduction to Objects, Arrays....57
Arrays....57
Getting the Length of an Array....58
Getting the Last Element of an Array....59
Array Manipulation Methods....60
Push and Unshift....61
Pop and Shift....61
Splice....62
Objects....63
Accessing Object Data....65
The Dot Notation vs. Square Brackets with Objects....66
Destructuring Objects....67
Object Mutability....69
Non-mutable objects....70
Spread Syntax or the “Three Dots”....72
Prototype-Based Programming....73
Prototypical Inheritance....75
[[Prototype]] vs. prototype (and __proto__)....77
Object Shallow and Deep Copies....79
Summary....82
Chapter 4: Loops and Iterables....83
Loops....83
Break and Continue in Loops....87
Loop Labels....87
Iteration....89
Iterables and For Loops....90
Array forEach methods....92
String Iteration....92
Iteration Protocol....93
Objects Are Not Iterable by Default....96
Summary....99
Chapter 5: References, Values, and Memory Management....100
Introduction....100
Stacks....101
The Event Loop....103
The Heap....106
Object and Reference Equality....107
Comparing Object Equality....109
Summary....110
Chapter 6: Functions and Classes....111
Introduction to Functions....111
Running Arguments with the “Three Dots”....114
Alternative Ways to Call Functions....114
Unnamed Function Expressions....115
Anonymous Functions....115
Functions with Arrow Notation....116
Functions and the “this” Keyword....116
Sloppy Mode....117
Arrow Notation Functionality with this....118
Calling Functions with Context....119
Constructor Functions in JavaScript....122
Additional Function Methods....125
Getters and Setters....126
Generator Functions....127
Classes....129
Classes and Constructor Functions....129
Class Methods....130
Class Method Types....133
Static Method Fields....134
Private Method Fields....136
Class Inheritance via Extends....136
Class Inheritance Super Keyword....139
Summary....141
Chapter 7: Types....142
Primitive Types....142
Primitive Wrappers....144
Using Wrappers to Create Types....147
The Number Type and NaN....148
Number Type Mathematics....150
Mathematical Methods....152
The Date Type....154
The Symbol Type....158
Truthy and Falsy Types....160
Truthy and Falsy Operators....161
Logical AND Operator....161
Logical OR Operator....162
Nullish Coalescing....163
Optionality....164
Summary....168
Chapter 8: Manipulating and Interacting with HTML....170
Window and Document Objects....170
The Window Object....171
The Document Object Model....173
Selecting HTML Elements....174
The Order of HTML....176
NodeLists and HTMLCollections....178
Manipulating HTML After Selection....181
Adding Events to HTML Elements....184
Creating a Modal Window....184
Creating a Counter....187
Event Types....188
Pointers, Touch, and Mouse....190
Event Capturing, Targeting, and Bubbling....191
Capturing Phase....194
Other Event Options....196
Live Data Using Events....198
Drag and Drop....201
The e variable....205
Creating New Elements with JavaScript....206
Manipulating CSS with JavaScript....210
HTMLElements and Changing Styles in JavaScript....210
Adding New Style Sheets to HTML Pages....211
Setting CSS Variables....211
Getting CSS Properties and HTML Dimensions....212
Summary....214
Chapter 9: Maps and Sets....216
Sets....216
Modifying Sets....218
Checking Set Membership....219
Checking Set Size....219
Merging Sets....219
Set Iteration and Values....220
Set Keys and Values....222
Maps....223
Retrieving Map Properties....226
Checking for Key Existence on a Map....228
Telling How Big a Javascript Map Is....228
Iterating, Merging, and Accessing Maps....229
Keys and Values in Maps....230
Serialization of Maps in JavaScript....232
Summary....233
Chapter 10: Fetching Data, APIs, and Promises....234
What Are APIs?....235
Understanding HTTP....237
RESTful Design....239
Understanding APIs Through a Node.JS Web Server....241
Testing Endpoints with Postman....247
The Benefits of APIs....247
Sending Data to APIs with JSON....249
The fetch Function....251
A Deep Dive into Fetch Options....254
body....255
mode....255
method....255
cache....256
credentials....256
headers....256
redirect....257
referrer....257
referrerPolicy....257
integrity....258
keepalive....258
Asynchronicity and Promises....259
Promise Methods: then, finally, and catch....261
catch and finally....262
The await Keyword....263
Useful Promise Methods....264
Promise.allSettled....265
Promise.all....266
Promise.race....267
Promise.any....268
Summary....269
Chapter 11: Introduction to Web APIs....270
Web APIs....270
Frequently Used Web APIs....272
URL API....273
Web Storage API....273
Web Notifications API....276
History API....277
Summary....278
Chapter 12: Errors and the Console....280
The Console Object....280
Console Errors, Debugs, Warnings, and Info....281
Console Tracing....281
Console Assertion....282
Console Timing....282
Console Counting....284
Other Useful Console Methods....285
Console Grouping....285
Console Tables....286
Errors and Exceptions....288
try…catch....289
finally....290
Generating Errors....292
Handling Specific Errors....293
Summary....294
Chapter 13: The Canvas....295
Introduction....296
Drawing and Images....298
Drawing Rectangles....298
Drawing Circles....301
Drawing Triangles....303
Drawing Images....305
Drawing Text....307
Interactivity and Creating a Drawing Application....309
Animations....313
Summary....315
Chapter 14: Web Workers and Multithreading....316
Introduction....316
Using Web Workers....318
Sending Messages to and from Web Workers....318
Restrictions on Web Workers....320
Conclusion....322
Index....323
JavaScript is a complicated language with a lot of misinformation surrounding how it works. This book provides a comprehensive introduction to JavaScript, from how it works at a technical level to how it is used to create websites and applications. Everything you need to know to start a career in JavaScript development is covered here.
How JavaScript Works begins with a practical introduction of the basics before moving into the technical underpinnings of JavaScript, detailing everything you need to know, including variables, memory storage, functions, classes, types, maps, sets and APIs. Once you’ve fully absorbed these key topics. author Jonathan Simpson will show you how to put them into practice, demonstrating how they are employed for modern web development. You’ll learn how to use JavaScript with HTML and CSS to construct web pages and applications, how to change CSS with JavaScript, and how to utilize Fetch and asynchronous operations.
Uponcompleting this book, you will have the foundational knowledge necessary to continue your journey to becoming a professional JavaScript developer.
Anyone interested in a web development career, as well as those who may have already embarked on their careers, but who want to deepen their technical understanding of JavaScript and how it works.