Errata

Learning JavaScript

Errata for Learning JavaScript

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 10
source code distributed over pp 8 - 10

I'm really not understanding why nobody has reported this - I've got Chrome and Firefox in Linux and seeing the same in both cases.

The image does not render unless the code such as
paper.setup('mainCanvas');
var cc = new Shape.Circle(100,125,50);
cc.fillColor = 'blue';
is wrapped in window.onload= function(){...}

The text says that wrapping in $(document).ready(function(){...} suffices, but in my experience it does not. (!!?!!)

As a JS newbie this was pretty nearly a showstopper for me. I am sure you must lose less experienced or committed programmers if they hit this point, so I guess for some unknown reason my experience is rare. But this is reliable from where I am sitting.

Happy to send along my files if this helps.

mtobis@gmail.com

Michael Tobis  Feb 13, 2018 
Printed Page 23
warning or caution paragraph

The command suggested for installing gulp with elevated privileges is listed as "sudo install -g gulp", but it should be "sudo npm install -g gulp".

Anonymous  Jan 14, 2017 
PDF Page 97
First Paragraph, Javascript code example

The provided JavaScript code example suggests running:

while((n = nums[i]) < 10, i++ < nums.length) {
console.log(`Number less than 10: ${n}.`);
}
console.log(`Number greater than 10 found: ${n}.`);
console.log(`${nums.length} numbers remain.`);

The while loop will never exit in case a number is greater than 10, because the comma operator that is used will only return the second expression's value. The logical AND operator should have been used instead:

while((n = nums[i]) < 10 && (i++ < nums.length))
...

Also, not sure what is the purpose of the last console.log statement:
console.log(`${nums.length} numbers remain.`);

Ioannes Bracciano  Jun 16, 2017 
PDF Page 103
second example

The comment misrepresents the outcome here.

const arr = [1, 2, 3];
arr[1] = getGreeting; // arr is now [1, function getGreeting(), 2]
arr[1](); // "Hello, World!"

In fact, arr is now [1, function getGreeting(), 3] (that is, the third element is 3, not 2).

FWIW, current versions of Chrome and Firefox display this differently from the way the comment above shows it. Chrome doesn't return the name of the function:

>arr

[1, <i>function</i>, 3]

Firefox does a little better, returning the name of the function, but not the word "function":

[1, <i>getGreeting()</i>, 3]

---Michael B.

Michael Bolton  Jan 25, 2017 
Printed Page 168
2nd paragraph

It says "To use this, we can use the typeof operator to determine if an instance of Error has been returned. "

The book than provides a code snippet that uses "instanceof", but not "typeof". I'm wondering if the "typeof" in the sentence from the book should be "instanceof".

Dylan Zwick  Dec 01, 2017 
Printed Page 173
Bottom paragraph

The text says "...and done, which becomes false after you read the last page."

Should be "...and done, which becomes TRUE after you read the last page."

Dylan Zwick  Dec 04, 2017 
Printed Page 219
Top of page.

At the top of page 219, in the 15th chapter on Date and Time, it says:

new Date(2015, 1, 14, 13); // 3:00 P.M., Feb 14, 2015

Why is an offset of 13 hours 3:00 PM? Seems like it should be 1:00 PM.

Dylan Zwick  Jan 15, 2018 
PDF Page 221
Code sample

before.d instanceof date
Should be:
before.d instanceof Date;

after.d instdanceof date
Should be:

after.d instanceof Date;

Worawit  Feb 10, 2018 
Printed Page 224
Top of page

At the top of the page it says:

// there are allso UTC equivalents to the above:

It should say:

// there are also UTC equivalents to the above:

Dylan Zwick  Jan 15, 2018 
Printed Page 225
Middle

In the examples of User-Friendly Dates, after the third example it switches from using fromNow() to using fromNOw(). I think there's a capitalization issue there.

Dylan Zwick  Jan 15, 2018 
247
the first and second examples in the Backreferences section

The example shown reads:

const promo = "Opening for XAAX is the dynamic GOOG! At the box office now!";
const bands = promo.match(/(?:[A-Z])(?:[A-Z])\2\1/g);

Similarly....

// we use backticks here because we're using single and
// double quotation marks:
const html = `<img alt='A "simple" example.'>` +
`<img alt="Don't abuse it!">`;
const matches = html.match(/<img alt=(?:['"]).*?\1/g);


When executed in the browser console, the const variables bands and matches receive the value of null. This is not what is ostensibly intended.

When we use backreferences, we do NOT want to use noncapturing groups. Both those examples should have the '?:' part of the regular expressions removed.

For example, after correcting this error, in the console we get:
bands = promo.match(/([A-Z])([A-Z])\2\1/g);
<-- Array [ "XAAX", "GOOG" ]

matches = html.match(/<img alt=(['"]).*?\1/g);
<-- Array [ "<img alt='A "simple" example.'", "<img alt="Don't abuse it!"" ]

A A Saraf  Mar 13, 2017