;Praise for Head First JavaScript Programming;Praise for other books by Eric T. Freeman and Elisabeth Robson;Authors of Head First JavaScript Programming;How to Use This Book: Intro; Who is this book for?; We know what you''re thinking.; Metacognition: thinking about thinking; Here''s what WE did:; Here''s what YOU can do to bend your brain into submission; Read Me; Tech Reviewers; AcknowledgmentsThe large number of acknowledgments is because we''re testing the theory that everyone mentioned in a book acknowledgment will buy at least one copy, probably more, what with relatives and everything. If you''d like to be in the acknowledgment of our next book, and you have a large family, write to us.;Chapter 1: Getting your feet wet; 1.1 The way JavaScript works; 1.2 How you''re going to write JavaScript; 1.3 How to get JavaScript into your page; 1.
4 JavaScript, you''ve come a long way baby.; 1.5 How to make a statement; 1.6 Variables and values; 1.7 Back away from that keyboard!; 1.8 Express yourself; 1.9 Doing things more than once; 1.10 How the while loop works; 1.
11 Making decisions with JavaScript; 1.12 And, when you need to make LOTS of decisions; 1.13 Reach out and communicate with your user; 1.14 A closer look at console.log; 1.15 Opening the console; 1.16 Coding a Serious JavaScript Application; 1.17 How do I add code to my page? (let me count the ways); 1.
18 We''re going to have to separate you two;Chapter 2: Going further; 2.1 Let''s build a Battleship game; 2.2 Our first attempt.; 2.3 First, a high-level design; 2.4 A few more details.; 2.5 Working through the Pseudocode; 2.
6 Oh, before we go any further, don''t forget the HTML!; 2.7 Writing the Simple Battleship code; 2.8 Now let''s write the game logic; 2.9 Step One: setting up the loop, getting some input; 2.10 How prompt works; 2.11 Checking the user''s guess; 2.12 So, do we have a hit?; 2.13 Adding the hit detection code; 2.
14 Hey, you sank my battleship!; 2.15 Provide some post-game analysis; 2.16 And that completes the logic!; 2.17 Doing a little Quality Assurance; 2.18 Can we talk about your verbosity.; 2.19 Finishing the Simple Battleship game; 2.20 How to assign random locations; 2.
21 The world-famous recipe for generating a random number; 2.22 Back to do a little more QA; 2.23 Congrats on your first true JavaScript program, and a short word about reusing code;Chapter 3: Getting functional; 3.1 What''s wrong with the code anyway?; 3.2 By the way, did we happen to mention FUNCTIONS?; 3.3 Okay, but how does it actually work?; 3.4 What can you pass to a function?; 3.5 JavaScript is pass-by-value.
; 3.6 Weird Functions; 3.7 Functions can return things too; 3.8 Tracing through a function with a return statement; 3.9 Global and local variables; 3.10 Knowing the scope of your local and global variables; 3.11 The short lives of variables; 3.12 Don''t forget to declare your locals!;Chapter 4: Arrays; 4.
1 Can you help Bubbles-R-Us?; 4.2 How to represent multiple values in JavaScript; 4.3 How arrays work; 4.4 How to access an array item; 4.5 Updating a value in the array; 4.6 How big is that array anyway?; 4.7 The Phrase-O-Matic; 4.8 Meanwhile, back at Bubbles-R-Us.
; 4.9 How to iterate over an array; 4.10 But wait, there''s a better way to iterate over an array; 4.11 It''s that time again. Can we talk about your verbosity?; 4.12 Redoing the for loop with the post-increment operator; 4.13 Quick test drive; 4.14 Creating an array from scratch (and adding to it); 4.
15 And the winners are.; 4.16 A quick survey of the code.; 4.17 Writing the printAndGetHighScore function; 4.18 Refactoring the code using printAndGetHighScore; 4.19 Putting it all together.;Chapter 5: A trip to Objectville; 5.
1 Did someone say "Objects"?!; 5.2 Thinking about properties.; 5.3 How to create an object; 5.4 What is Object-Oriented Anyway?; 5.5 How properties work; 5.6 How does a variable hold an object? Inquiring minds want to know.; 5.
7 Comparing primitives and objects; 5.8 Doing even more with objects.; 5.9 Stepping through pre-qualification; 5.10 Let''s talk a little more about passing objects to functions; 5.11 Oh Behave! Or, how to add behavior to your objects; 5.12 Improving the drive method; 5.13 Why doesn''t the drive method know about the started property?; 5.
14 How this works; 5.15 How behavior affects state. Adding some Gas-o-line; 5.16 Now let''s affect the behavior with the state; 5.17 Congrats on your first objects!; 5.18 Guess what? There are objects all around you! (and they''ll make your life easier);Chapter 6: Getting to know the DOM; 6.1 In our last chapter, we left you with a little challenge. The "crack the code challenge.
"; 6.2 So what does the code do?; 6.3 How JavaScript really interacts with your page; 6.4 How to bake your very own DOM; 6.5 A first taste of the DOM; 6.6 Getting an element with getElementById; 6.7 What, exactly, am I getting from the DOM?; 6.8 Finding your inner HTML; 6.
9 What happens when you change the DOM; 6.10 A test drive around the planets; 6.11 Don''t even think about running my code until the page is fully loaded!; 6.12 You say "event handler," I say "callback"; 6.13 How to set an attribute with setAttribute; 6.14 More fun with attributes! (you can GET attributes too); 6.15 So what else is a DOM good for anyway?;Chapter 7: Serious types; 7.1 The truth is out there.
; 7.2 Watch out, you might bump into undefined when you aren''t expecting it.; 7.3 How to use null; 7.4 Dealing with NaN; 7.5 It gets even weirder; 7.6 We have a confession to make; 7.7 Understanding the equality operator (otherwise known as ==); 7.
8 How equality converts its operands (sounds more dangerous than it actually is); 7.9 How to get strict with equality; 7.10 Even more type conversions.; 7.11 How to determine if two objects are equal; 7.12 The truthy is out there.; 7.13 What JavaScript considers falsey; 7.
14 The Secret Life of Strings; 7.15 How a string can look like a primitive and an object; 7.16 A five-minute tour of string methods (and properties); 7.17 Chair Wars (or How Really Knowing Types Can Change Your Life);Chapter 8: Building an app; 8.1 This time, let''s build a REAL Battleship game; 8.2 Stepping back. to HTML and CSS; 8.3 Creating the HTML page: the Big Picture; 8.
4 Adding some more style; 8.5 Using the hit and miss classes; 8.6 How to design the game; 8.7 Implementing the View; 8.8 How displayMessage works; 8.9 How displayHit and displayMiss work; 8.10 The Model; 8.11 How we''re going to represent the ships; 8.
12 Implementing the model object; 8.13 Setting up the fire method; 8.14 Implementing the Controller; 8.15 Processing the player''s guess; 8.16 Planning the code.; 8.17 Implementing parseGuess; 8.18 Counting guesses and firing the shot; 8.
19 How to add an event handler to the Fire! button; 8.20 Passing the input to the controller; 8.21 How to place ships; 8.22 Writing the generateShip method; 8.23 Generate the starting location for the new ship; 8.24 Completing the generateShip method;Chapter 9: Handling events; 9.1 What are events?; 9.2 What''s an event handler?; 9.
3 How to create your first event handler; 9.4 Test drive your event; 9.5 Getting your head around events. by creating a game; 9.6 Implementing the game; 9.7 Test drive; 9.8 Let''s add some more images; 9.9 Now we need to assign the same event handler to each image''s onclick property; 9.
10 How to reuse the same handler for all the images; 9.11 How the event object works; 9.12 Putting the event object to work; 9.13 Test drive the event object and target; 9.14 Events and queues; 9.15 Even more events; 9.16 How setTimeout works; 9.17 Finishing the image game; 9.
18 Test driving the timer;Chapter 10: Liberated functions; 10.1 The mysterious double life of the function keyword; 10.2 Function declarations versus function expressions; 10.3 Parsing the function declaration; 10.4 What''s next? The browser executes the code; 10.5 Moving on. The conditional; 10.6 How functions are values too; 10.
7 Did we mention functions have First Class status in JavaScript?; 10.8 Flying First Class; 10.9 Writing code to process and check passengers; 10.10 Iterating through the passengers; 10.11 Passing a function to a function; 10.12 Returning functions from functions; 10.13 Writing the flight attendant drink order code; 10.14 The flight attendant drink order code: a different approach; 10.
15 Taking orders with first class functions; 10.16 Webville Cola; 10.17 How the array sort method works; 10.18 Putting it all together; 10.19 Take sorting for a test drive;Chapter 11: Serious functions; 11.1 Taking a look at the other side of functions.; 11.2 How to use an anonymous function; 11.
3 We need to talk about your verbosity, again; 11.4 When is a function defined? It depends.; 11.5 What just happened? Why wasn''t fly defined?; 11.6 How to nest functions; 11.7 How nesting affects scope; 11.8 A little review of lexical scope; 11.9 Where things get interesting with lexical scope; 11.
10 Functions Revisited; 11.11 Calling a function (revisited); 11.12 What the heck is a closure?; 11.13 Closing a function; 11.14 Using closures to implement a magic counter; 11.15 Looking behind the curtain.; 11.16 Creating a closure by passing a function expression as an argument; 11.
17 The closure contains the actual environment, not a copy; 11.18 Creating a closure with an event handler; 11.19 How the Click me! closure works;Chapter 12: Creating objects; 12.1 Creating objects with object literals; 12.2 Using conventions for objects; 12.3 Introducing Object Constructors; 12.4 How to create a Constructor; 12.5 How to use a Constructor; 12.
6 How constructors work; 12.7 You can put methods into constructors as well; 12.8 It''s Production Time!; 12.9 Let''s test drive some new cars; 12.10 Don''t count out object literals just yet; 12.11 Rewiring the arguments as an object literal; 12.12 Reworking the Car constructor; 12.13 Understanding Object Instances; 12.
14 Even constructed objects can ha.