Errata

JavaScript: The Good Parts

Errata for JavaScript: The Good Parts

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
Other Digital Version N/A
N/A

The supplemental code linked by the text, and the O'Reilly catalog, at http://examples.oreilly.com/9780596517748/ appears to have been replaced by some kind of game. Not only does this game not have anything to do with the book, but it also fails to run.

Anonymous  Jun 26, 2015 
Other Digital Version Location 1001

It seems that at least in the Kindle edition (Nov 2016), a "new" method is added to to the Function object, but then it is not used when instantiating a new mammal object, instead the standard "new" constructor is used i.e. "new Mammal('Herb the Mammal')" when for educational reasons should have used "Mammal.new('Herb the Mammal')".

Soferio  Nov 17, 2016 
Printed Page qq
statments diagram

var statements is not used anywhere. I guess it should be listed as one option in the statements diagram.

DavidFarago  Dec 28, 2018 
Printed Page 1
5

Diagrams starting with "var statements" and continuing on from there, aren't clear as to where whitespace needs to be used. Rule 5 says that "diagrams with one bar at each end allow whitespace to be inserted between any pair of tokens" but whitespace isn't necessary. So this leads to some sequences that aren't legal even by following tracks.

Anonymous  Feb 10, 2018 
Other Digital Version 2.6
Second to last paragraph on the page

"The && operator produces the value of its first operand if the first operand is falsy. Otherwise, it produces the value of the second operand."

I noticed that in the errata someone had come close to catching this, but it seems they only submitted the first part of this statement. By itself, the first part of this is correct. However, the second sentence is where this statement becomes incorrect.

For example,

true && true
> true

false && true
> false

We're good so far...However,

true && false
> "false"

So, I think maybe there was a mix up between this statement and the following statement, which is for ||. It basically says the same thing; "The || operator produces the value of its first operand if the first operand is truthy. Otherwise, it produces the value of the second operand."


Bethany  Mar 29, 2024 
Printed Page 7
name grammar/rail diagram

Though the description is correct, the rail diagram for "name" need slight modification. The representation (in the rail diagram) for all name should start with letter is missing. Meaning I can make a name as following as per the current diagram shown, however this is error as per the language grammar in strict (or) non-strict mode.

"use strict";

var 73_i = 10;
var 53i = 20;

Karmegam  Nov 12, 2020 
Printed Page 8
integer grammar diagram

Hello:
The grammar diagram present for integer at page number 8 shall handle for negative number. If not representing for positive sign is okay, but its required to note for negative sign.

Some thing similar to denoted for exponent digit in exponent grammar.

Thanks,
Karmegam

Karmegam  Oct 26, 2020 
Printed, Page 9
"escaped character" railroad diagram

In the Strings section on Chapter 2 (Grammer), There is a railroad diagram marked "escaped character". One of the options is a forward slash ("/") which in fact is NOT escaped, and can be included in strings as-is.

Udi Finkelstein  Jan 02, 2017 
PDF Page 9
string literal railroad diagram

The tracks exiting "escaped character" should go back between the quote literal and the upper track, not after the upper track, otherwise one cannot specify a single escaped character.

Luis Tavera  Apr 17, 2020 
PDF Page 11
railroad diagram for: if statement

The lower loop in the 'if statement' railroad diagram is unnecessary: an if-statement nested within the else-block would semantically just be part of the else-block. Nested if-statements don't have any special semantics, so including the lower loop in the diagram is unnecessary and confusing. (Why is there no such loop for the then-block?)

The way it stands, the diagram amounts to letting the programmer omit the enclosing curly braces if there is another if-statement within the else-block. This isn't unreasonable, but it might not be what the author intended, and always using braces is (arguably) stylistically preferable.

Stephan Hyeonjun Stiller  Apr 13, 2024 
PDF Page 12
switch statement diagram

The diagram is saying the following situation would be impractical

var a = "1";
switch (a) {
case "1":
alert(a);
break;
},

since the diagram is not allowing to use only one case clause and finish it with a disruptive statement. Also it is acceptable use of "default" statement without a consecutive disruptive, as follows:

var a = "1";
switch (a) {
case "1":
alert(a);
default:
alert(a);
}

I really don't know whether it is a matter of a ECMAScript version or a tiny mistake. However, worth a look. Thanks!

Igor Andrade  Aug 31, 2014 
Printed Page 14-15
"Expression Statement" and "Expression" railroad diagrams

The lowest path of the "expression statement" railroad diagram shows that "delete {expression} {refinement}" is a legal expression statement; however, the "expression" railroad diagram shows that "delete {expression} {refinement}" is a legal expression. That suggests that "delete delete {expression} {refinement} {refinement}" would be a logical JavaScript statement.

Also (combined with the "for statement" railroad diagram on page 13), it suggests that "delete {expression} {refinement}" would be a legal increment clause for a for loop declaration.

Evan Turner  Jun 30, 2015 
Printed Page 15
First paragraph

An "or" should be added to the last clause of the first sentence, so it becomes, "invoke a method, or delete a property from an object."

Evan Turner  Jun 30, 2015 
Printed Page 20
2nd paragraph, last line

The text "A property value can be any JavaScript value except for undefined."
but the below code works without error. Hope this helps to correct the text.

"use strict";
var obj = {"":undefined};
alert(obj[""]);

Karmegam  Nov 12, 2020 
Printed Page 20
code

In the comfirmed errata at page 21, says:
It should be stooge["first-name"] // "Jerome"

In my opinion, this is not the better correction.
I perfer to change code at page 20:
"first-name": "Joe"

Why? because of at page 22, in the 2nd line:
... the property value is replaced:
stooge['first-name'] = 'Jerome';

which means: "Joe" is REPLACED by 'Jerome', natually.

Otherwise, "Jerome" is replaced by 'Jerome', which is almost meanless.

John Bao  Feb 26, 2022 
Other Digital Version 22,47,100,100
Just search the kindle version for 'beget' - all the instances found are errors

Although the Object.create/Object.beget confusion is marked in the errata sheet as being fixed in 2008, it still appears in the Kindle edition I bought in 2012. A search for 'beget' reveals 4 instances, all errors.

Anonymous  Aug 09, 2012 
Printed Page 22
"Prototype" section, second paragraph.

(This is not so much a mistake as a seriously-needed update.)

In the book, Object.create() is introduced as a helper function you can define in your code to make things saner. Since the book was first written, Object.create() has become a built-in method in many Javascript interpreters. It should be introduced that way, e.g. as follows:

Remove the two sentences, "The mechanism that Javascript provides to do this is messy and complex, but it can be significantly simplified. We will add a create method to the Object function."

Replace with the sentence, "Most modern Javascript interpreters provide an Object.create() method to do this." ("Object.create()" should be monospaced.)

At the end of the paragraph, before the code, add the sentence, "In case your Javascript doesn't support Object.create(), we can add it to the Object function." ("Object.create()" and "Object" should be monospaced.)

Steve Witham  Mar 28, 2014 
Printed Page 23
"Prototype" section, last paragraph before "Reflection" section.

"We will see more about the prototype chain in Chapter 6."

should be

"...in Chapter 5."

Steve Witham  Mar 28, 2014 
28
Paragraph starting at bottom of page ("When a function is invoked...")

This isn't a question or request for clarification. Instead, it's a comment about what I consider a confusing section.

The text starts with an example "add" function stored in the variable "sum". That's simple enough. The function is presented as a standalone top-level function.

The text then says that "this" is bound to the global object when this function is invoked. Still fine.

It continues with, "when **the inner function** (emphasis mine) is invoked." That's where the discussion is confusing. What inner function?

It's a confusing lead-in to a very important section about how to access members of the enclosing function from an inner function. But inner functions haven't been covered at that point.

On second and subsequent readings, this part of the book is understandable. The first time through, it's confusing.

It's still a great book.

Ron

Ron Stewart  Mar 04, 2014 
28
Paragraph starting at bottom of page ("When a function is invoked...")

Stupid me. I need to clarify my previous errata submission.

I said that the text starts with an example "add" function stored in the variable "sum." That's wrong.

I should have said that the text starts by showing a call to the example function "add" defined at the start of the chapter, and that that "add" function is a top-level, standalone function, not an inner function.

The rest of my previous submission says what I intended.

Ron

Ron Stewart  Mar 04, 2014 
PDF Page 33
middle of page

That regular express removes white space from both beginning and end of line. Not only end of line.

Farokh  Jan 30, 2017 
Printed Page 38,39
3rd paragraph of p. 38, 1st paragraph of p.39

3rd paragraph of p. 38:

'If it hasn't gotten to white yet...'

This implies that the author is taking us through the loop until level == 15.

1st paragraph of p.39

'But this time, fade's level is 2.'

Is it?





Bhakti Devananda  Sep 20, 2015 
ePub Page 39

Better example in closures section
modes[i] should be nodes[i].

Mark A. Baldridge  May 10, 2013 
ePub Page 39
line 8. Kindle edition

This error is in the Kindle edition and remains in the 2012 revision of the online code examples at http://examples.oreilly.com/9780596517748/

modes[i].onclick = helper(i);

should be:

nodes[i].onclick = helper(i);

Anonymous  Jun 01, 2014 
Mobi Page 47
code block

"?var that = Object.beget(this.prototype);" should be "?var that = Object.create(this.prototype);"

Anonymous  Sep 23, 2013 
Mobi Page 48
2nd code example

I get a 'TypeError: Number.integer is not a function' when running the following code:

Number.method('integer', function ( ) {
return Math[this < 0 ? 'ceil' : 'floor'](this);
});
(-10 / 3).integer( );

If integer is added directly to the prototype this way, then it works:

Number.prototype.integer = function ( ) {
return Math[this < 0 ? 'ceil' : 'floor'](this);
};
(-10 / 3).integer( ); //=> -3

Matt Morrow  Nov 23, 2013 
Printed Page 50
bottom code sample

myMammal object doesn't have a "saying" function so the the says function would not work unless augmented later as is done by the mycat object.

Don Kleppinger  Mar 22, 2013 
Printed Page 51
First paragraph.

This only makes sense if my suggestion to introduce Object.create() as a builtin on page 22, is taken.

Replace "the Object.create method from Chapter 3." with "the Object.create() method."

Steve Witham  Mar 28, 2014 
Printed Page 54
1st para of narrative, 2nd code listing

May 2008 edition
capitalization of Cat and Mamma1 does not agree between narrative and source code. Not sure which should change, probably the code so that the constructor functions are capitalized.

gwideman  Mar 29, 2012 
Printed Page 59
On Page 59 toward the bottom:

​The [] postfix subscript operator converts its expression to a string
using the expression's toString method if it has one.

​The word expression first indicates the contents of the brackets.

It is the object's toString method which is invoked.
The object in this case is an array. One could rewrite this method, which
is super cool.

So, I just recommend revising the sentence to:

​The [] postfix subscript operator converts the contents of the brackets to a string using the ​object's toString method if it has one.
In this case, the object is an array; the toString method is invoked coercing integers to Strings. Array['10'] and Array[10] are equivalent.​

Anonymous  Nov 25, 2014 
Printed Page 62
last paragraph, first sentence

This only makes sense if my suggestion to introduce Object.create() as a builtin on page 22, is taken.

(It also only makes sense if the modern Object.create() method still does not work on arrays!)

Replace "the Object.create method from Chapter 3" with "the Object.create() method".

Steve Witham  Mar 28, 2014 
Printed Page 64
Code example

Why do you iterate over the matrix created within the Array.identity function a second time explicitly setting the elements to 1?

Shouldn’t this do the trick as well:

Array.identity = function(n) {
return Array.matrix(n, n, 1);
}

Regards,
Stefan

Stefan Haberl  Oct 10, 2019 
Printed Page 66
First paragraph of section "An Example"

The regular expression "parse_url" raises the JSLint error "insecure" three times.
Should this regular expression not better be updated to match JSLint rules?
Suggestion: parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([a-zA-Z0-9.\-_~!$&\u0027()*+,;=:@\/%]*))?(?:\?([a-zA-Z0-9.\-_~!$&\u0027()*+,;=:@\/%]*))?(?:#([a-zA-Z0-9.\-_~!$&\u0027()*+,;=:@\/%]*))?$/;

Harms M?ller  Feb 25, 2014 
Printed Page 66
Parse url pattern

The group capturing the hostname should include an escaped \., because . alone will match any character

Stefan Haberl  Oct 10, 2019 
Printed Page 69
regular expression parse_number first line of first code example

The re "parse_number" on p.69 does not accept .78 or -.62
both of which are legal in many (all?) programming languages
including JavaScript. The repair is trivial and would not burden
the exposition. Please see the StrDecimalLiteral production in
97-028.pdf at the 1997 directory of the archives at ecma-international.org.

Suspected errata in Javascript the Good Parts by Douglas Crockford
submitted Apr 2021.
re: (c) 2008 printing history May 2008: First Edition
re: ISBN 978-0-596-51774-8

Roy Tobin  Apr 27, 2021 
Printed Page 72
top of the page

The make_a_matcher() example does not return 10 for y.lastIndex; instead, it returns 0. Maybe RegExp objects made by regular expression literals do not share a single instance?
See http://stackoverflow.com/questions/1326374/are-regex-literals-always-regexp-objects

Anonymous  May 06, 2013 
PDF, ePub Page 73
the last two paragraphs in "Regexp Factor" section

The text reads:

"An unescaped ^ matches the beginning of the text when the lastIndex property is zero. It can also match line-ending characters when the m flag is specified.

An unescaped $ matches the end of the text. It can also match line-ending characters when the m flag is specified."

It is identically stated of ^ and $ that they "can also match line-ending characters when the m flag is specified."

It would be more appropriate with ^ to specify that: "It can also match immediately after line-ending characters when the m flag is specified."

Alfredo Delgado  May 26, 2014 
74
3rd paragraph

The RegExp:
var doubled_words = /([A-Za-z\u00C0-\u1FFF\u2800-\uFFFD]+)\s+\1/gi;
will match any pair of identical strings of one or more letters separated by a space.

That means it will return many false positives where a substring at the end of one word matches a substring at the start of the following word. Matching false positives may prevent it from finding actual duplicated words.

For example:
"the end end".match(doubled_words);
returns ["e e"], a match against the last letter in "the" and initial letter in "end".
Consequently, it fails to match against the duplicated "end"s.

Cathal Murray  Dec 21, 2014 
Printed Page 75
Chapter 7, Regex class example

I believe this is a May 2008 print.
On the bottom of the page, under the "Could be written as:" the closing square bracket is not escaped. So it should be "\[|\\|\]" instead of "\[|\\|]". It's hard to spot, and I guess anybody get the gist of the example anyway.

Csaba Toth  Apr 28, 2013 
PDF Page 80
4.12.1 Paragraph 1

The word "propogates" should be "propagates".

myffical  Mar 25, 2013 
Printed Page 83
The whole page

I purchased a brand new printed copy through Amazon on 7/29/15 and received the book on 8/7/15. I am finally getting around to reading it. I finished page 82 and the next page was 99. I am literally missing pages 83 through 98. The book is brand new and the binding is in perfect condition. The pages were not torn out and non have fallen out due to a weakened binding. They were never inserted by the printer. Amazon.com LLC was the seller. I am putting in a complaint with Amazon.

Philip Krueger  Aug 27, 2015 
Printed Page 86
end of Object section

Erratum for my erratum about Object.create().

It should say "more an important update" not "more and".

Btw, the last paragraph there is part of the text I think should be inserted (not just commentary).

The reason I suggest adding an entry for Object.create is that if (as I suggest) you start treating Object.create as part of the language, a reader might then think page 86 is the logical place to look for info about it.

Steve Witham  Mar 30, 2014 
Printed Page 113
code

The function Expersson (second form):
var foo = function foo() {}; // A form

above experssion itself is fine, however, it is better to change as:
var foo = function () {}; // B form

The author claimed: "Throughout this book, I have been using the second form because it makes it clear ...". But throughout the book the author always used as B form and never as A form. B form is simple and clear, but A form is unclear and seems no explanation inside the book.

John Bao  Feb 26, 2022 
Mobi Page 139
3rd para from bottom

"produced the HTML. eval ing text" should be "produced the HTML. evaling text"

Anonymous  Sep 23, 2013 
Printed Page 151
Object.create() method

My copy says [2011-04-08].

The Object.create() index entry should list page 22 where Object.create() is introduced and explained. I haven't looked through the paper book for other missed instances, but 22 is the most important.

Steve Witham  Mar 28, 2014 
Printed Page 151
entry for "Obejct.create method

My edition says [2011-04-08].

If suggestion is taken to add Object.create entry on page 86, then add 86 to this entry in the index.

I see that if any number of lines were added to page 86, other entries on later pages would move to new pages! Hoping your index is automatic.

By the way, "If you lived in Github, you'd be accepting a pull-request by now."

Steve Witham  Mar 30, 2014