Exam JavaScript-Developer-I Topic 1 Question 72 Discussion
Actual exam question for Salesforce's JavaScript-Developer-I exam
Question #: 72
Topic #: 1
Question #: 72
Topic #: 1
Refer to the code below:
01 const objBook = {
02 title: ' JavaScript ' ,
03 };
04 Object.preventExtensions(objBook);
05 const newObjBook = objBook;
06 newObjBook.author = ' Robert ' ;
What are the values of objBook and newObjBook respectively?
01 const objBook = {
02 title: ' JavaScript ' ,
03 };
04 Object.preventExtensions(objBook);
05 const newObjBook = objBook;
06 newObjBook.author = ' Robert ' ;
What are the values of objBook and newObjBook respectively?
Suggested Answer: A Vote an answer
* Object.preventExtensions(obj) This built-in JavaScript method marks an object so that no new properties can be added to it. Existing properties can still be read and updated, but adding new ones is disallowed.
* const newObjBook = objBook; Both variables reference the same object in memory. JavaScript objects are assigned by reference, not copied.
* newObjBook.author = " Robert " ; Because the object has been marked as non-extensible, JavaScript will not allow new properties to be added. The behavior depends on mode:
* In non-strict mode: the assignment silently fails and does nothing.
* In strict mode: this would throw a TypeError.
Since nothing indicates strict mode, this is non-strict behavior, making the assignment fail silently.
Therefore, the object remains:
{ title: " JavaScript " }
Both objBook and newObjBook point to the same unchanged object.
This matches option A.
JavaScript knowledge references (text-only)
* Object.preventExtensions() prevents adding new properties.
* Assigning an object to another variable copies the reference, not the object.
* Adding a property to a non-extensible object silently fails in non-strict mode.
* const newObjBook = objBook; Both variables reference the same object in memory. JavaScript objects are assigned by reference, not copied.
* newObjBook.author = " Robert " ; Because the object has been marked as non-extensible, JavaScript will not allow new properties to be added. The behavior depends on mode:
* In non-strict mode: the assignment silently fails and does nothing.
* In strict mode: this would throw a TypeError.
Since nothing indicates strict mode, this is non-strict behavior, making the assignment fail silently.
Therefore, the object remains:
{ title: " JavaScript " }
Both objBook and newObjBook point to the same unchanged object.
This matches option A.
JavaScript knowledge references (text-only)
* Object.preventExtensions() prevents adding new properties.
* Assigning an object to another variable copies the reference, not the object.
* Adding a property to a non-extensible object silently fails in non-strict mode.
by Abel at Oct 01, 2026, 12:38 AM
0
0
0
10
Comments
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).