Errata

You Don't Know JS: Up & Going

Errata for You Don't Know JS: Up & Going

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
ePub Page 2
3rd para

Test

Anonymous  Sep 04, 2018 
Printed Page 19
1st paragraph code snippet

I'm new, so please let me know if there is a better way do this.

The code snippet:

const ACCESSORY_PRICE = 9.99;

var bank_balance = 302.13;
var amount = 99.99;

amount = amount * 2;

// can we afford the extra purchase?
if (amount < bank_balance) {
console.log("I'll take the accessory!");
amount = amount + ACCESSORY_PRICE;
}
// otherwise:
else {
console.log("No, thanks");
}

Should be changed to:

const ACCESSORY_PRICE = 9.99;

var bank_balance = 302.13;
var amount = 99.99;

amount = amount * 2;

// can we afford the extra purchase?
if (amount + ACCESSORY_PRICE < bank_balance) {
console.log("I'll take the accessory!");
amount = amount + ACCESSORY_PRICE;
}
// otherwise:
else {
console.log("No, thanks");
}


Without adding ACCESSORY_PRICE to amount in the 'if' statement, the conditional won't evaluate properly because ACCESSORY_PRICE is added to amount after the statement is evaluated.

To test this, I changed ACCESSORY_PRICE to 999.99 and the statement evaluated as true, even though that would ultimately exceed bank_balance.

I debugged with the following console.log() added in to make sure nothing was being changed unintentionally (i wasn't sure of the scope of the 'if' evaluation, if it would affect the variables, I'll get to that book soon):

if (amount + ACCESSORY_PRICE < bank_balance) {
console.log(amount);
console.log("I'll take the accessory!");
amount = amount + ACCESSORY_PRICE;
console.log(amount);
} else {
console.log("No, thanks");
}

Thanks.

Andrew Clunn  Jan 11, 2018 
PDF Page 26
bullet point 1

The first practice exercise is pretty unclear, and a confusing way to start the series. It says you'll keep purchasing until you run out of money in your bank account. The end result is a purchase amount is more than what you had in the bank account, which is really counter-intuitive to understand. Given the final output it should probably say "You'll keep purchasing until AFTER your run out of money..." This doesn't make sense from a practical standpoint, and an unexplained overdraft is a pretty bad way to make a cogent example for beginners.

Anonymous  Sep 25, 2017 
Printed Page 41
Hoisting

To improve one example in the book, consider the example on hoisting in Chapter 2 where:
var a = 2;
foo(); // works because 'foo()' declaration is "hoisted"

function foo()
{
a = 3;
console.log( a ); // 3

var a; // declaration is "hoisted" to the top of 'foo()'
}

console.log( a ); // 2


You might wish to augment the example with another which further clarifies
what you mean.

Using the code below, which merely removes the definition of a = 3:

var a = 2;
foo(); // works because 'foo()' declaration is "hoisted"

function foo()
{
// a = 3;
console.log( a ); // 3

var a; // declaration is "hoisted" to the top of 'foo()'
}

console.log( a ); // 2


This would _clearly_ show that the DECLARATION is hoisted, and not the
definition.

This type of error could lead to a bug which is difficult to detect.

Anonymous  Jul 23, 2018 
Printed, PDF, ePub, Mobi, Page 65
3rd paragraph

"password" in constant width at the end of the first line should not be broken over two lines.

Anonymous  Mar 27, 2019