<p>Introduction...................1</p> <p> Parlez-Vous JavaScript? 2</p> <p> Contacting Me/Getting Help...................... 2</p> <p>1 Hello, World!... 5</p> <p> What Is JavaScript?....... 7</p> <p> Hello, World!.................. 9</p> <p> Statements, Expressions, and Functions..12</p> <p> </p> <p><strong>I The Basic Stuff</strong></p> <p>2 Values and Variables..................... 15</p> <p> Using Variables............16</p> <p> More Variable Stuff......18</p> <p>3 Functions....... 23</p> <p> What Is a Function?.....26</p> <p> A Simple Function.......26</p> <p> Creating a Function That Takes Arguments...........................30</p> <p> Creating a Function That Returns Data...35</p> <p>4 Conditional Statements: if, else, and switch............... 39</p> <p> The If/Else Statement..40</p> <p> Switch Statements.......49</p> <p> Deciding Which to Use..............................55</p> <p>5 Looping with for, while, and do…while!...................... 57</p> <p> The for Loop................59</p> <p> The Starting Point........62</p> <p> Some for Loop Examples..........................64</p> <p> The Other Loops.........67</p> <p>6 Commenting Your Code…FTW!.... 71</p> <p> What Are Comments?.72</p> <p> Commenting Best Practices......................76</p> <p>7 Timers............ 79</p> <p> Delaying with setTimeout..........................80</p> <p>8 Variable Scope.............................. 85</p> <p> Global Scope...............86</p> <p> Local Scope..................88</p> <p> Miscellaneous Scoping Shenanigans.......89</p> <p>9 Closures......... 95</p> <p> Functions Within Functions.......................96</p> <p> When the Inner Functions Aren't Self-Contained................100</p> <p>10 Where Should Your Code Live?.. 109</p> <p> Approach #1: All the Code Lives in Your HTML Document...................113</p> <p> Approach #2: The Code Lives in a Separate File................114</p> <p> So, Which Approach to Use?..................118</p> <p>11 Console Logging Basics.............. 123</p> <p> Meet the Console......124</p> <p> Displaying the Console............................126</p> <p> If You Want to Follow Along...................127</p> <p> Console Logging 101..............................128</p> <p> </p> <p><strong>II It's an Object-Oriented World</strong></p> <p>12 Of Pizza, Types, Primitives, and Objects................... 135</p> <p> Let's First Talk About Pizza.......................136</p> <p> From Pizza to JavaScript!.........................139</p> <p> What Are Objects?....141</p> <p> The Predefined Objects Roaming Around in JavaScript....142</p> <p>13 Arrays.......... 145</p> <p> Creating an Array......146</p> <p> Accessing Array Values............................147</p> <p> Adding Items.............149</p> <p> Removing Items.........151</p> <p> Finding Items.............152</p> <p> Merging Arrays..........152</p> <p> Mapping, Filtering, and Reducing Arrays.............................153</p> <p> The Old School Way.153</p> <p> Modifying Each Array Item with map.....154</p> <p> Getting One Value from an Array of Items...........................157</p> <p> A Short Foray into Functional Programming........................160</p> <p>14 Strings......... 161</p> <p> The Basics...................162</p> <p> String Properties and Methods...............163</p> <p>15 Combining Strings and Variables 173</p> <p> Our Setup...................174</p> <p>16 When Primitives Behave Like Objects....................... 179</p> <p> Strings Aren't the Only Problem.............180</p> <p> Let's Pick on Strings Anyway...................180</p> <p> Why This Matters.......182</p> <p>17 Numbers...... 185</p> <p> Using a Number........186</p> <p> Operators...................187</p> <p> Incrementing and Decrementing............188</p> <p> Hexadecimal and Octal Values...............190</p> <p> Special Values—Infinity and NaN...........190</p> <p> The Math Object.......191</p> <p> Random Numbers.....196</p> <p>18 Getters and Setters.................... 201</p> <p> A Tale of Two Properties..........................202</p> <p> Meet Getters and Setters........................205</p> <p>19 A Deeper Look at Objects.......... 211</p> <p> Meet the Object........212</p> <p> Creating Custom Objects........................222</p> <p> The this Keyword.......226</p> <p>20 Using Classes.............................. 231</p> <p> The Class Syntax and Object Creation..232</p> <p> Extending Objects.....240</p> <p>21 Extending Built-in Objects.......... 247</p> <p> Say Hello to prototype Again, Sort Of!..249</p> <p> Using a Subclassing Approach................253</p> <p> Extending Built-in Objects Is Controversial................255</p> <p>22 Arrow Functions......................... 259</p> <p> What Are Arrow Functions?.....................260</p> <p> Putting It All Together..............................263</p> <p>23 Making Sense of this and More.. 265</p> <p> The this Keyword 101..............................266</p> <p>24 Booleans and the Stricter === and !== Operators... 277</p> <p> The Boolean Object..278</p> <p> The Boolean Function..............................278</p> <p> Strict Equality and Inequality Operators281</p> <p>25 Null and Undefined.................... 283</p> <p> Null..............................284</p> <p> Undefined...................284</p> <p>26 All About JSON (JavaScript Object Notation).......... 287</p> <p> What Is JSON?...........288</p> <p> Looking Inside a JSON Object...............292</p> <p> Reading JSON Data..297</p> <p> Writing JSON Data?..300</p> <p> </p> <p><strong>III Working with the DOM</strong></p> <p>27 JS, the Browser, and the DOM... 303</p> <p> What HTML, CSS, and JavaScript Do....304</p> <p> HTML Defines the Structure....................304</p> <p> Prettify My World, CSS!...........................306</p> <p> It's JavaScript Time!...307</p> <p> Meet the Document Object Model........309</p> <p>28 Finding Elements in the DOM.... 315</p> <p> Meet the querySelector Family...............316</p> <p> It Really Is the CSS Selector Syntax........318</p> <p>29 Modifying DOM Elements.......... 321</p> <p> DOM Elements Are Objects, Sort Of!....322</p> <p> Let's Actually Modify DOM Elements.....324</p> <p>30 Styling Our Content................... 337</p> <p> Why Would We Set Styles Using JavaScript?..............338</p> <p> A Tale of Two Styling Approaches..........338</p> <p>31 Using CSS Custom Properties.... 345</p> <p> What Are CSS Custom Properties/Variables?................346</p> <p> Setting Complex Values Easily................348</p> <p>32 Traversing the DOM................... 353</p> <p> Finding Your Way Around........................354</p> <p> Putting It All Together..............................358</p> <p>33 Creating and Removing DOM Elements.................... 363</p> <p> Creating Elements.....364</p> <p> Removing Elements..372</p> <p> Cloning Elements......374</p> <p>34 Quickly Adding Many Elements into the DOM......... 381</p> <p> General Approach.....383</p> <p> Getting Started..........384</p> <p>35 In-Browser Developer Tools........ 397</p> <p> Meet the Developer Tools.......................398</p> <p> </p> <p><strong>IV Dealing with Events</strong></p> <p>36 Events.......... 417</p> <p> What Are Events?......418</p> <p> Events and JavaScript..............................420</p> <p> A Simple Example.....423</p> <p> The Event Arguments and the Event Type.............426</p> <p>37 Event Bubbling and Capturing... 429</p> <p> Event Goes Down, Event Goes Up........430</p> <p> Meet the Phases........434</p> <p> Who Cares?................437</p> <p> Event, Interrupted.....438</p> <p>38 Mouse Events............................. 443</p> <p> Meet the Mouse Events...........................444</p> <p> The MouseEvent Properties....................451</p> <p> Dealing with the Mouse Wheel..............454</p> <p>39 Keyboard Events........................ 457</p> <p> Meet the Keyboard Events......................458</p> <p> Using These Events...459</p> <p> The Keyboard Event Properties..............460</p> <p> Some Examples.........461</p> <p>40 Page Load Events and Other Stuff............................ 467</p> <p> The Things That Happen During Page Load..........468</p> <p> The DOMContentLoaded and load Events................471</p> <p> Scripts and Their Location in the DOM.473</p> <p> Script Elements: async and defer...........477</p> <p>41 Loading Script Files Dynamically 481</p> <p> The Basic Technique.482</p> <p> Running Our Dynamically Loaded Script First............486</p> <p> Running Dependent Code After Our Script File Has Loaded........488</p> <p>42 Handling Events for Multiple Elements..................... 491</p> <p> How to Do All This....493</p> <p> </p> <p><strong>V Totally Useful Topics that Only Make Sense Now</strong></p> <p>43 Using Emojis in HTML, CSS, and JavaScript.............. 501</p> <p> What Are Emojis Exactly?........................502</p> <p> Emojis in HTML..........503</p> <p>44 Making HTTP/Web Requests in JavaScript................ 511</p> <p> The Example..............513</p> <p> Meet Fetch.................514</p> <p> Meet XMLHttpRequest............................520</p> <p>45 Accessing the Webcam............... 529</p> <p> The Example..............530</p> <p> Overview of How This Works..................531</p> <p> Adding the Code.......532</p> <p> Examining the Code.535</p> <p>46 Array and Object Destructuring. 539</p> <p> Destructuring Examples...........................541</p> <p>47 Storing Data Using Web Storage.............................. 549</p> <p> How Web Storage Works........................550</p> <p> Getting Your Code On.............................552</p> <p>48 Variable and Function Hoisting.. 559</p> <p> JavaScript and Compiler Behavior.........560</p> <p>49 Working with Sets...................... 565</p> <p> Creating a Set, Part I.566</p> <p> Adding Items to a Set..............................567</p> <p> How Checking for Duplicates Works......567</p> <p> Creating a Set, Part 2569</p> <p> Checking the Size of Our Set..................570</p> <p> Deleting Items from a Set.......................571</p> <p> Checking If an Item Exists.......................572</p> <p> Looping Through Items in a Set.............572</p> <p> Entries, Keys, and Values.........................573</p> <p>50 Conclusion... 577</p> <p>Glossary............................ 581</p> <p> </p> <p>9780137959167, TOC, 10/13/2022</p>