Strict Mode?

Get help with Code for Teens
Post Reply
mkeCharlie
Posts: 1
Joined: Thu Jun 04, 2020 2:34 am

Strict Mode?

Post by mkeCharlie » Thu Jun 04, 2020 2:44 am

I just bought this book for my teenager, and was going through the first chapter this week before him. In the "Simple Errors" section of Chapter 1, I could not reproduce the Identifier has already been declared error with the syntax given. I tried to invoke strict mode in the console, but it didn't seem to "take," and the only way I could get that favoriteColor changing error was to declare a function, and invoke "use strict"; within the function body.

Code: Select all

let favoriteColor = "red";
// Response: undefined // no problem yet (undefined just means "nothing to tell you")
let favoriteColor = "blue";
// Response is supposed to be: Uncaught SyntaxError: Identifier 'favoriteColor' has already been declared
// I just get Response: undefined again!
Did I miss a step where you can configure the Chrome dev tools JS console to be in strict mode? Is there an errata published for the book? Did I miss something? Please advise.

JeremyMoritz
Site Admin
Posts: 20
Joined: Mon May 14, 2018 10:19 pm
Location: Kansas
Contact:

Re: Strict Mode?

Post by JeremyMoritz » Sat Mar 27, 2021 2:42 pm

Very observant, mkeCharlie!

Since the book was published, Chrome has gotten more forgiving about reassigning with `let`. It doesn't throw the error anymore. The practice hasn't changed; just Chrome's implementation of it.

Thanks!

Jeremy
Jeremy Moritz
Author of Code for Teens
www.CodeForTeens.com

Post Reply