Exam JavaScript-Developer-I Topic 4 Question 93 Discussion
Actual exam question for Salesforce's JavaScript-Developer-I exam
Question #: 93
Topic #: 4
Question #: 93
Topic #: 4
A class was written to represent items for purchase in an online store, and a second class representing items that are on sale at a discounted price. The constructor sets the name to the first value passed in. There is a new requirement for a developer to implement a description method that will return a brief description for Item and SaleItem.
01 let regItem = new Item( ' Scarf ' , 55);
02 let saleItem = new SaleItem( ' Shirt ' , 80, .1);
03 Item.prototype.description = function() { return ' This is a ' + this.name; }
04 console.log(regItem.description());
05 console.log(saleItem.description());
06
07 SaleItem.prototype.description = function() { return ' This is a discounted ' + this.name; } What is the output when executing the code above?
01 let regItem = new Item( ' Scarf ' , 55);
02 let saleItem = new SaleItem( ' Shirt ' , 80, .1);
03 Item.prototype.description = function() { return ' This is a ' + this.name; }
04 console.log(regItem.description());
05 console.log(saleItem.description());
06
07 SaleItem.prototype.description = function() { return ' This is a discounted ' + this.name; } What is the output when executing the code above?
Suggested Answer: B Vote an answer
Comprehensive and Detailed Explanation:
Assuming SaleItem inherits from Item via prototype (e.g. SaleItem.prototype = Object.create(Item.prototype)):
* Lines 01-02: create regItem and saleItem.
* Line 03: define Item.prototype.description.
Now both regItem and saleItem (via inheritance) have a description method from Item.prototype.
* Line 04: regItem.description() # ' This is a Scarf ' .
* Line 05: saleItem.description() # ' This is a Shirt ' (same method, but this.name is ' Shirt ' ).
* Line 07: SaleItem.prototype.description = ... overrides description only for SaleItem instances going forward.
If we imagine calling regItem.description() and saleItem.description() again after line 07:
* regItem.description() still uses Item.prototype.description # ' This is a Scarf ' .
* saleItem.description() now uses SaleItem.prototype.description # ' This is a discounted Shirt ' .
Those four lines correspond to option B.
Assuming SaleItem inherits from Item via prototype (e.g. SaleItem.prototype = Object.create(Item.prototype)):
* Lines 01-02: create regItem and saleItem.
* Line 03: define Item.prototype.description.
Now both regItem and saleItem (via inheritance) have a description method from Item.prototype.
* Line 04: regItem.description() # ' This is a Scarf ' .
* Line 05: saleItem.description() # ' This is a Shirt ' (same method, but this.name is ' Shirt ' ).
* Line 07: SaleItem.prototype.description = ... overrides description only for SaleItem instances going forward.
If we imagine calling regItem.description() and saleItem.description() again after line 07:
* regItem.description() still uses Item.prototype.description # ' This is a Scarf ' .
* saleItem.description() now uses SaleItem.prototype.description # ' This is a discounted Shirt ' .
Those four lines correspond to option B.
by Carter at Sep 28, 2026, 10:26 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).