...

/

Solution Review: "strict" Mode

Solution Review: "strict" Mode

In this lesson, we will discuss the solutions to the questions in the previous lesson.

Question 1: Solution review #

In the previous lesson, you were given the following code:

Press + to interact
"use strict"
var obj1 = {};
Object.defineProperty(obj1, 'x', { value: 42, writable: false });
obj1.x = 9;

For the code above, you had to answer the following question.

Explanation #

Let’s run the code to see what happens.

Press + to interact
"use strict"
var obj1 = {};
Object.defineProperty(obj1, 'x', { value: 42, writable: false });
obj1.x = 9;

As you can see, an error is thrown when the code is run; this means Option A is correct. Why do you see an error?

The answer might seem obvious; since, on line 3, when we define the property x, we set its writable property to false; this ...

Access this course and 1400+ top-rated courses and projects.