Skip to content

Tagged Template Literal Function Skips Final Static String Segment in Output #9

@aaqib605

Description

@aaqib605

The tagged template literal function fails to include the final static string segment ("?") from the strings array in its output. This happens because the function explicitly references only specific indices (strings[0] and strings[1]), omitting the last segment.

function tag(strings, ...values) {
  return strings[0] + values[0] + strings[1] + values[1];
}

const result = tag`Hello ${'world'}! How are ${'you'}?`;
console.log(result); // "Hello world! How are you?"

To get the desired log statement stated above the tag function should look like the following

function tag(strings, ...values) {
  return strings[0] + values[0] + strings[1] + values[1] + strings[2];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions