First, compute sampleText:
let codeName = ' Bond ' ;
let sampleText = `The name is ${codeName}, Jim ${codeName}`;
The template literal evaluates to:
" The name is Bond, Jim Bond "
Now evaluate each statement:
Option A: sampleText.includes( ' Jim ' );
String.prototype.includes(substring) returns true if substring occurs anywhere in the string.
sampleText clearly contains " Jim " ( " The name is Bond, Jim Bond " ).
So this returns true.
Option B: sampleText.includes( ' The ' , 1);
includes(searchString, position) starts searching from the given position index.
" The name is Bond, Jim Bond " has " The " starting at index 0.
Starting search at index 1 means " The " at index 0 is not considered, and there is no second " The " .
So this returns false.
Option C: sampleText.includes( ' Jim ' , 4);
" Jim " appears after " The name is Bond, " which is longer than 4 characters; the index of " Jim " is well past 4.
So when searching from index 4, " Jim " is still found.
This returns true.
Option D: sampleText.indexOf( ' Bond ' ) !== -1;
String.prototype.indexOf(substring) returns:
-1 if the substring is not found,
Otherwise, the starting index of the first occurrence.
" Bond " appears twice in " The name is Bond, Jim Bond " .
So sampleText.indexOf( ' Bond ' ) is some non-negative index (for the first occurrence).
Therefore indexOf( ' Bond ' ) !== -1 is true.
Option E: sampleText.substring( ' Jim ' );
substring expects numeric indexes: substring(startIndex, endIndex?).
If given a string " Jim " as the argument, JavaScript coerces it to a number:
So sampleText.substring( ' Jim ' ) is effectively sampleText.substring(0), which returns the full string " The name is Bond, Jim Bond " .
This is a string , not a boolean. The question asks “which code statements return true?”
This statement returns a string, not the boolean value true.
Thus, the three statements that actually return true (boolean) are:
Answer: A, C, D
Study Guide / Concept References (no links):
Template literals and ${} interpolation
String.prototype.includes(searchString, position?)
String.prototype.indexOf(substring) and checking for !== -1
String.prototype.substring(start, end?) and argument coercion
Boolean vs non-boolean return types in string methods