Introduction 1 Parlez-vous JavaScript? 2Contacting Me/Getting Help 4 Chapter 1 Hello, World! 5 What Is JavaScript? 7A Simple Example 8Code Editing Tools 8The HTML Document 9Looking at the Code: Statements and Functions 10 PART I: THE BASIC STUFFChapter 2 Values and Variables 13 Using Variables 14More Variable Stuff 15Naming Variables 15More on Declaring and Initializing Variables 16 Chapter 3 Functions 19 What Is a Function? 22A Simple Function 22Creating a Function That Takes Arguments 24Creating a Function That Returns Data 27The Return Keyword 27Exiting the Function Early 28 Chapter 4 Conditional Statements: If, Else, and Switch 31 The If/Else Statement 32Meet the Conditional Operators 34Creating More Complex Expressions 36Variations on the If/Else Statement 38Phew 39Switch Statements 39Using a Switch Statement 39Similarity to an If/Else Statement 42Deciding Which to Use 44 Chapter 5 Meet the Loops: For, While, and Do.While! 47 The for Loop 49The Starting Condition 51Terminating Condition (aka Are we done yet?) 51Reaching the End 51Putting It All Together 52Some for Loop Examples 52Stopping a Loop Early 53Skipping an Iteration 53Going Backwards 54You Don''t Have to Use Numbers 54Array! Array! Array! 54Oh No He Didn''t! 55The Other Loops 55The while Loop 56The do.while Loop 56 Chapter 6 Timers 59 Meet the Three Timers 60Delaying with setTimeout 60Looping with setInterval 61Animating Smoothly with requestAnimationFrame 62 Chapter 7 Variable Scope 67 Global Scope 68Local Scope 70Miscellaneous Scoping Shenanigans 71Declarations Using var Do Not Support Block Scoping 71How JavaScript Processes Variables 72Closures 74 Chapter 8 Closures 77 Functions within Functions 78When the Inner Functions Aren''t Self-Contained 81 Chapter 9 Where Should Your Code Live? 89 The Options on the Table 90Approach #1: All the Code Lives in Your HTML Document 92Approach #2: The Code Lives in a Separate File 93The JavaScript File 93Referencing the JavaScript File 94So Which Approach to Use? 97Yes, My Code Will Be Used on Multiple Documents! 97No, My Code Is Used Only Once, on a Single HTML Document! 99 Chapter 10 Commenting Your Code 101 What Are Comments? 102Single Line Comments 103Multi-line Comments 104Commenting Best Practices 106 PART II: IT''S AN OBJECT-ORIENTED WORLDChapter 11 Of Pizza, Types, Primitives, and Objects 109 Let''s First Talk About Pizza 110From Pizza to JavaScript 113What Are Objects? 115The Predefined Objects Roaming Around 117 Chapter 12 Strings 121 The Basics 122String Properties and Methods 124Accessing Individual Characters 124Combining (aka Concatenating) Strings 125Making Substrings out of Strings 126Splitting a String/split 128Finding Something Inside a String 129Upper and Lower Casing Strings 130 Chapter 13 When Primitives Behave Like Objects 133 Strings Aren''t the Only Problem 134Let''s Pick on Strings Anyway 134Why This Matters 137 Chapter 14 Arrays 139 Creating an Array 140Accessing Array Values 141Adding Items to Your Array 143Removing Items from the Array 145Finding Items in the Array 146Merging Arrays 147 Chapter 15 Numbers 149 Using a Number 150Operators 151Doing Simple Math 151Incrementing and Decrementing 152Special Values--Infinity and NaN 153Infinity 153NaN 154The Math Object 154The Constants 155Rounding Numbers 157Trigonometric Functions 158Powers and Square Roots 158Getting the Absolute Value 159Random Numbers 59 Chapter 16 A Deeper Look at Objects 161 Meet the Object 162Creating Objects 163Specifying Properties 167Creating Custom Objects 169The this Keyword 175 Chapter 17 Extending Built-in Objects 179 Say Hello to Prototype.Again--Sort of! 181Extending Built-in Objects Is Controversial 185You Don''t Control the Built-in Object''s Future 186Some Functionality Should Not Be Extended or Overridden 186 Chapter 18 Booleans and the Stricter === and !== Operators 189 The Boolean Object 190The Boolean Function 190Strict Equality and Inequality Operators 192 Chapter 19 Null and Undefined 195 Null 196Undefined 197 Chapter 20 Immediately Invoked Function Expressions 201 Writing a Simple IIFE 203Writing an IIFE That Takes Arguments 204When to Use an IIFE 205Avoiding Code Collisions 206Closures and Locking in State207Making Things Private 213 PART III: WORKING WITH THE DOMChapter 21 JS, The Browser, and The DOM 219 What HTML, CSS, and JavaScript Do 220HTML Defines the Structure 220Prettify My World, CSS! 222It''s JavaScript Time! 223Meet the Document Object Model 225The Window Object 227The Document Object 228 Chapter 22 Finding Elements in the DOM 231 Meet the querySelector Family 232querySelector 233querySelectorAll 233It Really Is the CSS Selector Syntax 234 Chapter 23 Modifying DOM Elements 237 DOM Elements Are Objects--Sort of! 238Let''s Actually Modify DOM Elements 240Changing an Element''s Text Value 242Attribute Values 242 Chapter 24 Styling Your Content 247 Why Would You Set Styles Using JavaScript? 248A Tale of Two Styling Approaches 248Setting the Style Directly 249Adding and Removing Classes Using classList 250Adding Class Values 250Removing Class Values 251Toggling Class Values 251Checking Whether a Class Value Exists 252Going Further 252 Chapter 25 Traversing the DOM 255 Finding Your Way Around 256Dealing with Siblings and Parents 259Let''s Have Some Kids!259Putting It All Together 261Checking Whether a Child Exists 261Accessing All the Child Elements 261Walking the DOM 262 Chapter 26 Creating and Removing DOM Elements 265 Creating Elements 266Removing Elements 271Cloning Elements 273 Chapter 27 In-Browser Developer Tools 279 Meet the Developer Tools 280Inspecting the DOM 282Debugging JavaScript 287Meet the Console 293Inspecting Objects 294Logging Messages 296 PART IV: DEALING WITH EVENTSChapter 28 Events 299 What Are Events? 300Events and JavaScript 3021. Listening for Events 3022. Reacting to Events 304A Simple Example 305The Event Arguments and the Event Type 307 Chapter 29 Event Bubbling and Capturing 311 Event Goes Down Event Goes Up 312Meet the Phases 316Who Cares? 319Event, Interrupted 319 Chapter 30 Mouse Events 325 Meet the Mouse Events 326Clicking Once and Clicking Twice 326Mousing Over and Mousing Out 328The Very Click-like Mousing Down and Mousing Up Events 330The Event Heard Again.and Again.and Again! 331The Context Menu 332The MouseEvent Properties 333The Global Mouse Position 333The Mouse Position Inside the Browser 334Detecting Which Button Was Clicked 335Dealing with the Mouse Wheel 336 Chapter 31 Keyboard Events 339 Meet the Keyboard Events 340Using These Events 341The Keyboard Event Properties 342Some Examples 343Checking That a Particular Key Was Pressed 343Doing Something When the Arrow Keys Are Pressed 344Detecting Multiple Key Presses 345 Chapter 32 Page Load Events and Other Stuff 349 The Things That Happen During Page Load 350Stage Numero Uno 351Stage Numero Dos 352Stage Numero Three 352The DOMContentLoaded and load Events 353Scripts and Their Location in the DOM 355Script Elements--Async and Defer 358async 358defer 359 Chapter 33 Handling Events for Multiple Elements 363 How to Do All of This 365A Terrible Solution 366A Good Solution 367Putting It All Together 370 Chapter 34 Conclusion 373Glossary 377Index 381.
JavaScript Absolute Beginner's Guide