Skip to content

Conversation

@aaqib605
Copy link
Contributor

@aaqib605 aaqib605 commented Dec 23, 2024

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];
}

Fixes #9

@yangshun yangshun changed the title fix: tagged templates code example contents: fix tagged templates code example Jan 8, 2025
Copy link
Member

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you!

@yangshun yangshun merged commit 50faa54 into greatfrontend:main Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tagged Template Literal Function Skips Final Static String Segment in Output

2 participants