We start with:
let productSKU = ' 8675309 ' ;
The requirement:
We can use String.prototype.padStart and String.prototype.padEnd:
str.padStart(targetLength, padString)
If str.length < targetLength, it adds padString to the start until the length is targetLength.
str.padEnd(targetLength, padString)
Similar, but adds padString to the end.
We want a pattern like:
First, pad the numeric part out to a fixed length with zeros.
Then, pad to total length with ' sku ' at the start.
productSKU = productSKU.padStart(16, ' 0 ' ).padStart(19, ' sku ' );
Step 1: productSKU.padStart(16, ' 0 ' )
Initial productSKU is ' 8675309 ' (length 7).
After padStart(16, ' 0 ' ), we pad zeros on the left to reach length 16.
We need 16 − 7 = 9 zeros:
Result after step 1:
productSKU === ' 0000000008675309 ' // length 16
Step 2: .padStart(19, ' sku ' )
Now productSKU has length 16.
We call padStart(19, ' sku ' ):
We need 19 − 16 = 3 extra characters.
The pad string ' sku ' is exactly 3 characters, so it is added as-is at the start.
Result after step 2:
productSKU === ' sku0000000008675309 ' // length 19
This satisfies:
Length 19.
Starts with ' sku ' .
Remaining characters are zeros plus the original digits, i.e. a zero-padded numeric section.
While the literal sample sku000000008675309 in the text has a slightly different count of zeros, Option B follows the requirement pattern:
3 characters of ' sku '
Numeric part padded with zeros to make 16 characters total for the numeric part
3 + 16 = 19 total characters
Option B matches the intended logic using padStart and padEnd.
Option A:
productSKU = productSKU.padEnd(16, ' 0 ' ).padStart( ' sku ' );
padEnd(16, ' 0 ' ) produces ' 8675309000000000 ' (original number followed by zeros).
padStart( ' sku ' ) is invalid usage:
padStart takes a numeric target length as the first argument, not a string.
Passing ' sku ' as the first argument leads to type coercion that does not achieve the intended behavior.
This will not reliably produce the desired SKU.
Option C:
productSKU = productSKU.padEnd(16, ' 0 ' ).padStart(19, ' sku ' );
First padEnd(16, ' 0 ' ) from ' 8675309 ' gives ' 8675309000000000 ' (length 16, zeros at the end).
Then padStart(19, ' sku ' ) adds 3 chars ' sku ' at the front:
This string starts with ' sku ' , but the zeros are at the end of the digits, not padding the numeric part on the left as desired.
Option D:
productSKU = productSKU.padStart(19, ' 0 ' ).padStart( ' sku ' );
First padStart(19, ' 0 ' ) pads zeros at the left to make the length 19.
Then padStart( ' sku ' ) again incorrectly uses a string where a numeric targetLength is required.
This will not produce the correct SKU format.
Therefore, the only option that correctly uses padStart to create a 16-character zero-padded numeric portion and then a 19-character string starting with ' sku ' is:
Answer: B
References / Study Guide concepts (no links):
String.prototype.padStart(targetLength, padString)
String.prototype.padEnd(targetLength, padString)
String length calculations
Left-padding numeric strings with zeros
Building prefixed identifiers with fixed total length