Errata

Head First JavaScript Programming

Errata for Head First JavaScript Programming

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF, 585

I'm a bit confused about the logic here. If the dogs start standing, why is the text "is already sitting" since this.sitting will return false and not true?

Dog.prototype.sitting = false; //dogs start standing

Dog.prototype.sit = function() {
if (this.sitting) {
//doesn't this mean "if this.sitting is false, i.e. if the dogs are standing"?
console.log(this.name + " is already sitting.");
} else {
this.sitting = true;
console.log(this.name + " is now sitting.");
}
}

Thanks,
Tyga

Tyga  Jul 20, 2017 
Other Digital Version 27

In howdy.html, there is an extra </body> tag in the downloadable files. The correct code should read:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Howdy</title>
</head>
<body>
<script>
message = "Howdy" + " " + "partner";
console.log(message);
</script>
</body>
</html>

Greg Raven  Dec 14, 2017 
PDF Page 87 and 118
Inside the body of the function

Code Magnets (chapter 3)

There is no article "a" for the code:
console.log("Wear t-shirt");
It should be:
console.log("Wear a t-shirt");

This mistake happens to both the problem and solution pages, that is 87 and 118 respectively.

Alvin Ampang  Jul 13, 2022 
Printed Page 130
Could be page 162? Annotation under the array beginning "Notice..."

In the Russian translation of Head First JavaScript Programming, according to one reader, on page 162 (which I think is page 130 in the English version), the annotation says "Notice that because we start numbering the indices of the array at 0, the length of the array will always be one LESS than the last index."

In my English copy on page 130 this annotation properly says "one MORE than the last index". This is correct.

So I think this is an error in the Russian translation.

I don't have a copy of the Russian translation so can't verify this.

Elisabeth Robson
Elisabeth Robson
 
Jan 30, 2020 
Mobi Page 199.4/722
3rd paraphraph

In the "Initializing a primitive variable" paragraph, there is a section that refers to the "Initializing an object (a reference) variable"
The "When you declare and initialize an object...." repeats twice

Below is a copy paste of the entire section:

Initializing a primitive variable
When you declare and initialize a primitive, you give it a value, and that value goes right in the cup, like this: When you declare and initialize an object, you make the object using object notation, but that object won’t fit in the cup. So what goes in the cup is a reference to the object.

Initializing an object (a reference) variable
When you declare and initialize an object, you make the object using object notation, but that object won’t fit in the cup. So what goes in the cup is a reference to the object.

Alexandros Vasileiou  Apr 07, 2019 
Printed Page 352
2 paragraph 1st line of code

Starting from pg. 349, you start the controller code (at the bottom of page) which states: var controller = {processGuess: function(guess){//more code here}}; this is an object with a method inside correct?, but on pg 352 it's written like this function processGuess(guess){//code here...}; which looks like a regular function not inside an object. Then on pg. 356 it's back to the object method again. Which one is it?

jfly28  Jan 21, 2019 
Printed Page 354
in function parseGuess

On page 354 of Head First JavaScript Programming, function parseGuess has three ineffectual error tests: isNan(row), row >= model.boardSize, and column < 0. The other tests row < 0, isNan(column), and column >= model.boardSize are necessary but inadequate. An additional check for the error condition column === " " is needed as well.

Garth Peterson  Dec 05, 2017 
PDF Page 381
second to last row

"we're going rethink our approach" should be
"we're going to rethink our approach"

Diana  Oct 09, 2017 
Printed Page 392
code for the collision method (Russian edition, page may vary)

This errata was already reported (submitted Jun 29, 2016), but somehow it has a very dramatic effect on my code. When I write

var ship = this.ships[i];

collision method works fine and it indeed does not allow any collisions. But when I write

var ship = model.ships[i]; (as stated in my version of book)

the collisions happen! I tested it several times and there are a lot of collisions when using model.ships[i] instead of this.ships[i].
An example:

(3) [{…}, {…}, {…}]
0:
hits: (3) ["", "", ""]
locations: (3) ["31", "32", "33"]
__proto__: Object
1:
hits: (3) ["", "", ""]
locations: (3) ["50", "51", "52"]
__proto__: Object
2:
hits: (3) ["", "", ""]
locations: (3) ["33", "43", "53"]
__proto__: Object
length: 3
__proto__: Array(0)

How is it possible? Switching from "this" to "model" is the only change I made in my code and I cannot understand why it has such an impact.

Marina  Nov 07, 2018 
PDF Page 486
5th paragraph of image's caption on right hand side of it.

quacker is only defined here.

It should be deleted, as quacker defined before, at the end of expressed function not at the end of declared function.

Vahid Kamyab  Jun 25, 2021 
Printed Page 518
Bottom right comment with arrow

"Oh, and it returns "More please" should be "Oh, and it alerts "More please". The function doesn't "return" anything.

Jeff  Sep 05, 2017 
PDF Page 535
end

I'm not a native English speaker, but I think "Now now" stands for "Not now" at the end of the interview

Daniel Riaño  Jun 16, 2021 
PDF Page 543
Last paragraph, 1st sentence

Original: "As it turns out, one of the things the new operator does behind the scenes when the object is created is to store information that allows it to determine, at any time, the constructor that created the object."

This, IMHO, implies that instanceof could be used to find out which constructor was used to create a certain object. In my understanding instanceof can only be used to check if an object was created by a *certain* constructor.

Suggested change:

"As it turns out, one of the things the new operator does behind the scenes when the object is created is to store information that allows it to check, at any time, if an object was created by a certain constructor."

Jørgen W. Lang  Aug 22, 2014 
PDF Page 610

How does (phrase.cliche()) translate into returning true if the string contains a known cliché? How is this comparing what's in the sentences array with what's in the cliche function?

for (var i = 0; i < sentences.length; i++) {
var phrase = sentences[i];
if (phrase.cliche()) {
console.log("CLICHE ALERT: " + phrase);
}
}

Thanks,
Tyga

Tyga  Jul 20, 2017 
PDF Page 621
Code for Palindrome method

var len = this.length - 1;
the explanation says "First we get the length of the string". Length of the string is anyway calculated by "this.length"..the explanation for minus 1 is not there so it becomes a bit ambiguous. In y humble opinion it should be "First we get the length of the character array, for which we do this.length - 1 since index starts from 0 in Javascript"

Aseem Sharma  Nov 11, 2017 
PDF, ePub, Mobi Page 3650
text

Current
To do that, we typically assign the element to a variable so we can refer to the element thoughout our code.

Suggested
"the element thoughout our code." should be "the element throughout our code."

Anonymous  Sep 16, 2019