Book description
What will you learn from this book?
Now in its second edition, this brain-friendly guide is your comprehensive journey into modern JavaScript, covering everything from the core language fundamentals to cutting-edge features that define JavaScript today. You'll dive into the nuances of JavaScript types and the unparalleled flexibility of its functions. You'll learn how to expertly navigate classes and objects, and you'll finally understand closures. But that's just the beginning—you'll also get hands-on with the browser's document object model (DOM), engaging with JavaScript in ways you've only imagined. You won't just be reading—you'll be playing games, solving puzzles, pondering mysteries, and interacting with JavaScript. And you'll write real code, lots of it, so you can start building your own web applications.
What's so special about this book?
If you've read a Head First book, you know what to expect: a visually rich format designed for the way your brain works. If you haven't, you're in for a treat. With this book, you'll learn JavaScript through a multisensory experience that engages your mind—rather than a text-heavy approach that puts you to sleep.
Publisher resources
Table of contents
- Brief Table of Contents (Not Yet Final)
-
1. A Quick Dip into Javascript: Getting your Feet Wet
- The way JavaScript works
- How you’re going to write JavaScript
- How to get JavaScript into your page
- A little test drive
- JavaScript, you’ve come a long way...
- How to make a statement
- Variables and values
- Constants, another kind of variable
- Back away from that keyboard!
- Express yourself
- Doing things more than once
- How the while loop works
- Making decisions with JavaScript
- And, when you need to make LOTS of decisions
- Reach out and communicate with your user
- A closer look at console.log
- Opening the console
- Coding a Serious JavaScript Application
- How do I add code to my page? (let me count the ways)
- We’re going to have to separate you two
- JavaScript cross
- JavaScript cross Solution
-
2. Writing Real Code: Going Further
- Let’s build a Battleship game
- Our first attempt...
- First, a high-level design
- A few more details...
- Working through the Pseudocode
- Oh, before we go any further, don’t forget the HTML!
- Writing the Simple Battleship code
- Now let’s write the game logic
- Step One: setting up the loop, getting some input
- How prompt works
- Checking the user’s guess
- So, do we have a hit?
- Adding the hit detection code
- Hey, you sank my battleship!
- Provide some post-game analysis
- And that completes the logic!
- Doing a little Qualit y Assurance
- Can we talk about your verbosit y...
- Finishing the Simple Battleship game
- How to assign random locations
- The recipe for generating a random number
- Back to do a little more QA
- Congrats on your first true JavaScript program, and a short word about reusing code
- JavaScript cross
- JavaScript cross Solution
-
3. Introducing Functions: Getting functional
- What’s wrong with the code anyway?
- By the way, did we happen to mention FUNCTIONS?
- Okay, but how does it actually work?
- Code Magnets
- What can you pass to a function?
- JavaScript is pass-by-value
- Weird Functions
- Functions can return things too
- Tracing through a function with a return statement
- Global and local variables
- Knowing the scope of your local and global variables
- There’s more to the story: any block can act as the scope of a variable
- Don’t forget to declare your locals!
- The short lives of variables
- The Thing-A-Ma-Jig
- Who am I?
- Five Minute Mystery
- JavaScript cross
- Code Magnets Solution
- The Thing-A-Ma-Jig
- Five Minute Mystery Solution
- Who am I? Solution
- JavaScript cross Solution
-
4. Putting some order in your Data: Arrays
- Can you help Bubbles-R-Us?
- How to represent multiple values in JavaScript
- How arrays work
- How to access an array item
- Updating a value in the array
- How big is that array anyway?
- The Phrase-O-Matic
- Meanwhile, back at Bubbles-R-Us...
- Cubicle Conversation
- How to iterate over an array
- But wait, there’s a better way to iterate over an array
- Test drive the bubble report
- Fireside Chats
- It’s that time again.... Can we talk about your verbosity?
- Redoing the for loop with the post-increment operator
- Quick test drive
- Cubicle Conversation Continued...
- Creating an array from scratch (and adding to it)
- Test drive the final report
- And the winners are...
- A quick survey of the code...
- Writing the printAndGetHighScore function
- Refactoring the code using printAndGetHighScore
- Putting it all together...
- JavaScript cross
- JavaScript cross Solution
-
5. Understanding Objects: A trip to Objectville
- Did someone say “Objects”?!
- Thinking about properties...
- How to create an object
- What is Object-Oriented Anyway?
- How properties work
- How does a variable hold an object? Inquiring minds want to know...
- Behind the Scenes
- Comparing primitives and objects
- Behind the Scenes
- Doing even more with objects...
- Doing some pre-qualification
- Does the taxi cut it?
- Stepping through pre-qualification
- Let’s talk a little more about passing objects to functions
- Putting Fido on a diet....
- The Auto-O-Matic
- The Auto-O-Matic
- Oh Behave! Or, how to add behavior to your objects
- Improving the drive method
- Take the fiat for a test drive
- Uh oh, not so fast...
- Why doesn’t the drive method know about the started property?
- A test drive with “this”
- How this works
- Method shorthand
- How behavior affects state... Adding some Gas-o-line
- Now let’s affect the behavior with the state
- Gas up for a test drive
- Congrats on your first objects!
- Guess what? There are objects all around you! (and they’ll make your life easier)
- Crack the Code Challenge
- JavaScript cross
- JavaScript cross Solution
-
6. Interacting with your web page: Getting to know the DOM
- In our last chapter, we left you with a little challenge. The “crack the code challenge.”
- So what does the code do?
- A quick recap
- How JavaScript really interacts with your page
- How to bake your very own DOM
- A first taste of the DOM
- Getting an element with getElementById
- What, exactly, am I getting from the DOM?
- Finding your inner HTML
- What happens when you change the DOM
- A test drive around the planets
- Don’t even think about running my code until the page is fully loaded!
- You say “event handler,” I say “callback”
- Why stop now? Let’s take it further
- So what else is a DOM good for anyway?
- JavaScript cross
- JavaScript cross Solution
-
7. Types, Equality, Conversion and all that Jazz: Serious Types
- The truth is out there...
- Who am I?
- Watch out, you might bump into undefined when you aren’t expecting it...
- How to use null
- Believe It or Not!! The Number that isn’t a Number
- Dealing with NaN
- It gets even weirder
- We have a confession to make
- Understanding the equality operator (other wise known as ==)
- How equality converts its operands (sounds more dangerous than it actually is)
- How to get strict with equality
- Even more type conversions...
- How to determine if two objects are equal
- The truthy is out there...
- What JavaScript considers falsey
- The Secret Life of Strings
- How a string can look like a primitive and an object
- How template literals work
- A five-minute tour of string properties and methods
- String Soup
- Chair Wars
- JavaScript cross
-
8. Bringing it all Together: Building an app
- This time, let’s build a REAL Battleship game
- Stepping back... to HTML and CSS
- Creating the HTML page: the Big Picture
- Step 1: The Basic HTML
- Step 2: Creating the table
- Step 3: Player interaction
- Adding some more style
- Step 4: Placing the hits and misses
- Using the hit and miss classes
- How to design the game
- Implementing the View
- How displayMessage works
- Implementing displayMessage
- How displayHit and displayMiss work
- Implementing displayHit and displayMiss
- Another Test Drive...
- The Model
- How the model interacts with the view
- You’re gonna need a bigger boat... and game board
- How we’re going to represent the ships
- Ship Magnets
- Implementing the model object
- Thinking about the fire method
- Setting up the fire method
- Looking for hits
- Putting that all together...
- Wait, can we talk about your verbosity again?
- Meanwhile back at the battleship...
- A view to a kill...
- Implementing the Controller
- Processing the player’s guess
- Planning the code...
- Implementing parseGuess
- Meanwhile back at the controller...
- Counting guesses and firing the shot
- Game over?
- Getting a player’s guess
- How to add an event handler to the Fire! button
- Getting the player’s guess from the form
- Passing the input to the controller
- What’s left? Oh yeah, darn it, those hardcoded ships!
- Code Magnets
- How to place ships
- Writing the generateShip method
- Generate the starting location for the new ship
- Completing the generateShip method
- Avoiding a collision!
- Two final changes
- Congrats, It’s Startup Time!
- JavaScript cross
- JavaScript cross Solution
- About the Authors
Product information
- Title: Head First JavaScript Programming, 2nd Edition
- Author(s):
- Release date: September 2024
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781098147945
You might also like
book
Head First JavaScript Programming
What will you learn from this book? This brain-friendly guide teaches you everything from JavaScript language …
book
Head First HTML and CSS, 2nd Edition
Tired of reading HTML books that only make sense after you're an expert? Then it's about …
book
Learning JavaScript Design Patterns, 2nd Edition
Do you want to write beautiful, structured, and maintainable JavaScript by applying modern design patterns to …
video
Learn JavaScript
4+ Hours of Video Instruction JavaScript started as a basic language for performing simple computations on …