Errata

JavaScript: The Definitive Guide

Errata for JavaScript: The Definitive Guide

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
Printed Page Page xiv
The icons indicating a tip or warning

On page 447, there is a warning with a scorpion icon but this icon is not part of the two icons listed on page xiv.

I am not sure if the wasp icon on page xiv is synonymous with the scorpion icon I've encountered on page 447.

This appears to either be an inconsistency with the usage of these icons or the scorpion icon was accidentally not included on page xiv.

Emrah Abdurahman  Feb 09, 2022 
ePub Page n/a
2 typos

1.
Current Copy
of digits followed by a lowercase letter n. By default, the are in base 10, but you can use the 0b,

Suggested
"default, the are in base 10, but you can use the 0b, 0o," should be "default, they are in base 10, but you can use the 0b, 0o,"

2.
Current Copy
synchronous code can. And this is why Promises are designed the way the are. The value of a fulfilled Promise is like the return

Suggested
"why Promises are designed the way the are. The value of" should be "why Promises are designed the way they are. The value of"

Anonymous  Mar 25, 2022 
Printed Page page 27
section 3.2.3, 1st paragraph, line 1

delete stray period in “operators . that”

Tim Stewart  Nov 15, 2022 
Printed Page page 29
last paragraph (starting “The negative zero value”)

p. 29, last paragraph (starting “The negative zero value”): bad break between lines 1 and 2 in “Jav-aScript’s”

Tim Stewart  Nov 15, 2022 
Printed Page page 31
first full paragraph (starting “BigInt literals are written”)

p. 31, first full paragraph (starting “BigInt literals are written”), line 2: change “the” to “they” in “the are in base 10”

Tim Stewart  Nov 15, 2022 
Printed Page page 62
2nd group of code font lines (starting with “true”)

p. 62, 2nd group of code font lines (starting with “true”), line 1: fix “Evalutes” to “Evaluates”

Tim Stewart  Nov 15, 2022 
Printed Page Page 110
Last paragraph under the heading "for/of with strings"

Strictly speaking, should "UTF-16 character" and "UTF-16 characters" be "UTF-16 code unit[s]"?

Joe Barnes  Nov 17, 2022 
Printed, PDF Page Page 365
4th line from the bottom

The variable "url" is bound to the same variable of the for loop. Thus, when "fetchOne(url)" is executed, the value of the variable "url" is always the last element of the array "urls".

To fix the bug, you can declare a local variable within the for loop to capture each value of elements in "urls":

for(url of urls) {
let _url = url;
p = p.then(() => fetchOne(_url));
}

Zhiliang Xu  Jan 03, 2023 
PDF Page p.214, section 8.8.1
First code snippet

The formula to compute the standard deviation takes the size of the array minus one. It shoudn't be minus one, just the size of the array:
let stddev = Math.sqrt(total/(data.length-1));

Anonymous  Jan 09, 2023 
PDF Page Page 152
Last paragraph

In the last paragraph of section 6.10.6, the snippet comment reads :

"The expression "random.octet", for example, yields a random number between 0 and 255 each time it is evaluated."

However, the range is 0-256 if Math.random() evaluates to 1: Math.floor(Math.random()*256);

Here's the full snippet of the book:
// This object has accessor properties that return random numbers.
// The expression "random.octet", for example, yields a random number
// between 0 and 255 each time it is evaluated.
const random = {
get octet() { return Math.floor(Math.random()*256); },
get uint16() { return Math.floor(Math.random()*65536); },
get int16() { return Math.floor(Math.random()*65536)-32768; }
};

Charles  Jan 09, 2023 
PDF Page Page 193
Last paragraph

The paragraph provides a way to easily test for an existing array, and to assign it to a variable, or, if no array exists, create a new one: a = a || [];
The problem is the explanation uses the word "object" instead of "array":

"In this case, if any object is passed as the second argument, the function will use that object"

Charles  Jan 09, 2023 
PDF Page Page §8.5, on p.204
Last paragraph of the section

Typo: "within that namesapce"

Charles  Jan 09, 2023 
PDF Page page 23
last paragraph

Any JavaScript value that is not a number, a string, a boolean, a symbol, null, or unde
fined is an object. => should include also bigint as primitive type.

Davide  Feb 06, 2023 
PDF Page page 24
last paragraph

But numbers, strings, boolean, and symbol values behave as if
they have methods. => should include also bigint.

Davide  Feb 06, 2023 
ePub, Page Chapter 13. Asynchronous JavaScript
Second paragraph under section number 13.3

This was submitted in March 2022 as one of a two-part submission and is unconfirmed. The first item in the submission is clear as entered.

The original submission wasn't clear on the actual typo and was (for me) difficult to identify. This resubmission is for clarification.

:The existing text:
"And this is why Promises are designed the way the are."

:The corrected text:
"And this is why Promises are designed the way they are."

** Note the corrected spelling from "the" to "they".

Douglas Schneider  May 16, 2023 
PDF Page p.239, Section 9.5.2
2nd §

The author talks about a function, but it is a class, not a function:

"This is a new feature enabled by ES6 class syntax: EZArray() is a function, but it inherits from Array()"

Charles  Jul 22, 2023 
Printed Page 3
first 4 words

My instinct is that 'by making HTTP requests' should be 'to make HTTP requests'

Loren Cannon  Jun 29, 2022 
7.1.2 The Spread Operator
3rd paragraph

In my opinion, in
"The spread operator is a convenient way to create a (shallow) copy of an array:"
replace shallow by deep?
Gives
"The spread operator is a convenient way to create a (deep) copy of an array:"

Dietmar  Sep 02, 2023 
Printed Page 9.3.3, p234
2nd code example

The last line of the definition of static parse(s) should read:

return new Range(parseInt(matches[1]), parseInt(matches[2]));

(In the printed version, Range was given the second argument, matches[2] , without parsing it, though matches[1] was parsed.)

Michael R Lewy  Jun 17, 2023 
PDF Page 11.6.1 JSON Customizations
4th paragraph's example code

/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\dZ$/.test(value)) {
the "." should be "\." in regular expression to match a literal dot:
/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\dZ$/.test(value)) {

Anonymous  Jan 23, 2023 
Printed Page 12
4th paragraph

Example code 1-1:
On page 12 book states "In a unix-type environment you can invoke the program like this: node charfreq.js < corpus.txt"
I am using windows and do not have file named "corpus.txt". Can you please tell me how I run this code on Windows? I am using visual studio code with node installed.

Simon  Jun 24, 2022 
Printed Page 43
Section 3.8, 1st and 2nd line

Quote: "There is a fundamental difference in JavaScript between primitive values (undefined, null, booleans, numbers and strings) ..." - In the parenthesis, only 5 out of 6 primitive data types are listed (at the time of writing) - Symbol being the omitted one.

thewebmasterp  Jun 07, 2022 
Printed Page 110
for/of with strings

In this section, « UTF-16 character » does not mean an actual character, which is confusing. Contrast with pages 32 & 35, which call them just "16-bit values" instead. It seems to be a confusion coming from the habit of using a type named `char` in Java, or the `charAt` method in both Java and Javascript.

Mathieu Bouchard  May 22, 2022 
Printed Page 128
Blank page

Page 128 is not printed. Page 127 before it is printed. Next pages 129-132’s bind loose and fallen off when open. I can take photos of the book to show.

May I have a print of pg 128 that is missing?

HARYATI HASSAN  Jan 22, 2022 
PDF Page 137
last paragraph

Attempting to set a property on null or undefined also causes a TypeError.
in the middle of pag 140: let o = {x: undefined};
And in my console i can set a property's object to undefined or null.

Davide Pedrotti  Feb 13, 2023 
Printed Page 215
8.8.2

On Wikipedia, "Higher-order function" includes also any function that takes a function as a parameter, regardless of whether it also returns a function. From a quick search, this seems to be the definition used everywhere in every programming language, with the exception of the many people who are quoting The Definitive Guide.

This means that map() and reduce() in 8.8.1 are themselves higher-order. This can't be corrected by just replacing "and" by "and/or" in the 1st sentence of 8.8.2 : it seems like higher-order functions should be in the heading 8.8 (e.g. as "Functional Programming and Higher-Order Functions"), and then heading 8.8.2 would be "Functions that return a function".

Mathieu Bouchard  May 22, 2022 
PDF Page 215
First function example (function "not")

The third line of function "not" reads:
let result = f.apply(this, args);

And I first thought that it would be easier simply to write:
let result = f(...args);

I thought that "f.apply(this, args);" would make the function work with objects. But it is not the case. For example, if I have this object:

let ob = {x:2,
even() {return this.x % 2 === 0},
odd() {return not(this.even)()}
}

then, the expression:

ob.odd()

always return "true", no matter the value of ob.x. (And the reason, as I have checked, is because "this" is always the object "window": in the function "not", and in the function that "not" returns, and in the function that that function invoques.)

To make that the function "not" work in this case, we can change the method "odd" in the ob object like so:

odd() {return not( this.even.bind(this) )()}

With that change, all works, no matter the third instruction in "not" is

let result = f.apply(this, args); or
let result = f(...args)

I comment all this because when I saw the line of code "let result = f.apply(this, args);", instead of the easier one "let result = f(...args)", I thought that was for cases with objects involved. But as I've showed, that's not the case

Joaquin Moreno  Jan 18, 2023 
Printed Page 279
2nd paragraph

Suggestion to add an opening and closing parenthesis after the word subarray.

Emrah Abdurahman  Jan 06, 2022 
ePub Page 279
Section 8.7.7, 3rd bullet at end of section

In the last bullet, there is this sample code (comments removed, call to console.log added for debugging):

let scope = "global";
function constructFunction() {
let scope = "local";
return new Function("return scope");
}
console.log(constructFunction()());

This code produces the expected result when run in Chrome (98.0.4758.109, arm64). However, when I run it in Node.js v17.6.0 (macOS 12.2.1, Apple M1), it gives me the following error:

undefined:3
return scope
^
ReferenceError: scope is not defined
at eval (eval at constructFunction (.../test.js:4:12), <anonymous>:3:1)
at Object.<anonymous> (.../test.js:6:32)

Anonymous  Feb 24, 2022 
Printed Page 303
2nd paragraph

The second to last sentence of the second paragraph states the following:
"To do date arithmetic involving days, months, and years, you can use setDate(), setMonth(), and setYear()".

Issue: I think the setYear() method should be stated as setFullYear(). There is a "setYear()" method but according to MDN it is deprecated.

Emrah Abdurahman  Jan 13, 2022 
Printed Page 314
3rd paragraph

1st sentence of the second paragraph of section 11.7.3.

Add the word "to" after the word enough so it says "...it is not enough to use the sort() method".

Emrah Abdurahman  Jan 14, 2022 
Printed, PDF Page 344
3rd line of code

I think third line of code should be:

versionCallback(request.statusText, null);

instead of
versionCallback(response.statusText, null);

Joaquin Moreno  Nov 15, 2022 
Printed Page 345
2nd code block example

At the start of the getText() function, the request variable is declared without a let, const, or var keyword.

My question is, is this intentional or was one of these keywords omitted by mistake?

Emrah Abdurahman  Jan 20, 2022 
Printed Page 346
2nd line of Page (example code)

The code comment contains an erroneous repetition of the word „to“: „So we register more event handlers to to be called…“ -

Christian Gabrisch   Jan 22, 2022 
Printed Page 350
2nd paragraph

Regarding the second sentence of the second paragraph of the "Promise Terminology" section.

I would suggest to add the word "of" in between "ways" and "registering callbacks" for this sentence to sound more natural.

Emrah Abdurahman  Jan 21, 2022 
Printed Page 357
First line

On page 357, top line, code is
if (type !== "application/json") {

'type' can include more text, like "application/json; charset=UTF-8".

Test may be changed to
if (type.indexOf("application/json") < 0) {

Jan Ottar Lingjærde  Mar 15, 2024 
Printed Page 423
Last paragraph at the bottom of page 423

Change "should to be aware of" to "should be aware of".

Emrah Abdurahman  Feb 05, 2022 
Printed Page 442
"children" section near the top of the page

The children property returns an HTMLCollection rather than a NodeList according to MDN:

https://developer.mozilla.org/en-US/docs/Web/API/Element/children

Emrah Abdurahman  Feb 08, 2022 
Printed Page 443
3rd paragraph

The paragraph describing the childNodes property has a duplicate "that" word.

Emrah Abdurahman  Oct 06, 2021 
Printed Page 458
3rd paragraph

Error in HTML code:
<div id="subscribe" class="fadable notification">...</div>

If corrected like this, the JavaScript code in paragraph 4 will work as intended:
<div id="subscribe" class="fadable">notification ...</div>

Tor Galaasen  Nov 06, 2023 
Printed Page 477
1st comment

Change "customElement.define()" on the first comment line to "customElements.define()" to match the property name.

Emrah Abdurahman  Feb 19, 2022 
Printed Page 490
Caption of Figure 15-9

Change the caption of Figure 15-9 from "The lineCap and lineJoin attributes" to "The lineCap and lineJoin properties".

Emrah Abdurahman  Feb 21, 2022 
Printed Page 508
First comment

Suggestion to change "audioContext" to "AudioContext" as this is reflecting the object itself and not the variable name.

Emrah Abdurahman  Mar 02, 2022 
Printed, PDF Page 521
Setting request headers - The search function

There might be an error with the part 'let url = new URL("/api/search");' in the search function as the URL() constructor receives an absolute URL string as the argument or a relative URL as the first argument and the absolute URL that it is relative to as the second argument. Please help check.

Simon Nguyen  Jul 15, 2023 
PDF Page 529
15.11.2 Server-Sent Events, 3rd paragraph

```diff
- The event object also has a `type` property
+ The event object also has a `event` property
```

Anonymous  Apr 17, 2023 
Printed Page 544
4th and 5th full paragraphs

In the 4th and 5th full paragraphs on page 544, the IDBRange object is mentioned. I think this object's API name is IDBKeyRange according to MDN:

https://developer.mozilla.org/en-US/docs/Web/API/IDBKeyRange

Emrah Abdurahman  Mar 16, 2022 
Printed Page 545
Caption of Example 15-13

Change "A IndexedDB..." to "An IndexedDB..." for the title of Example 15-13.

Emrah Abdurahman  Mar 16, 2022 
Printed Page 645
17.7 First paragraph

The word „of“ is repeated mistakenly: „This section explains what you need to know to make sense of of it.“

Christian Gabrisch   Jun 20, 2022