Possible small error on JavaScript ES6 Course

Hello Campers :slight_smile:

I was taking the JS ES6 course and stumbled upon a (possible) small error on this page:

It says: “Once the object is frozen, you can no longer add, update, or delete properties from it. Any attempt at changing the object will be rejected without an error.”

But in fact, there WILL be an arror if one tries to modify a frozen object: so that might be wrong, or if I am, maybe please help me out? :slight_smile:

Also, if this is not the correct section for this kind of content, please redirect me towards the correct one

Best wishes and happy camping <3

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

Thank you for the reply, also I am not sure this is even a bug because when executing the code in a Chrome console, for example, I am not getting any errors: so maybe I should turn this into a question about when does the error happen and when not

Unfortunately, I don’t know enough to know exactly what sort of ‘error’ it counts as or what the best way to phrase what happens is with respect to JavaScript nomenclature. I just see that an exception is raised that says [TypeError: "PI" is read-only] when logged. So it looks? like an error?

Welcome, there.

This is not so much a bug as it is just a bit unclear what is happening for freeCodeCamp’s specific setup.

Behind the scenes, the JS you write in the editor is executed in "use strict" mode. This mode is, as the names suggests, strict.

This is why you see no error in the browser console. The mode has to be explicitly set, in order for the error to appear.

Hope this clarifies

2 Likes

Yes, this is correct! :slight_smile: Thank you so much, in fact when setting the “use strict” mode in the console I see the error, and when use strict is not used, there is none.

I’ll also leave here a snippet to set the “use strict” inside a Chrome console, since “use strict” alone won’t really work:
(function(){

“use strict”;

let obj = {
name:“FreeCodeCamp”,
review:“Awesome”
};
Object.freeze(obj);
obj.review = “bad”; // will throw an exception
})()