0% found this document useful (0 votes)
1 views2 pages

What Is A Template String in Advanced JavaScript

A template string, or template literal, is an ES6 feature that enhances string creation by allowing variable embedding, multi-line strings, and string expressions. They are defined using backticks (`) instead of traditional quotes. Examples demonstrate how to use template strings for creating personalized greetings and combining function outputs within strings.

Uploaded by

raisedeven
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

What Is A Template String in Advanced JavaScript

A template string, or template literal, is an ES6 feature that enhances string creation by allowing variable embedding, multi-line strings, and string expressions. They are defined using backticks (`) instead of traditional quotes. Examples demonstrate how to use template strings for creating personalized greetings and combining function outputs within strings.

Uploaded by

raisedeven
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is a Template String in Advanced JavaScript?

A template string (also called a template literal) is a


feature introduced in ES6 (ECMAScript 2015) that
allows easier and more readable string creation,
especially when:
 Embedding variables into strings
 Writing multi-line strings
 Using string expressions or functions inside strings

Syntax
Template strings are defined using backticks (`) instead of
single (') or double (") quotes.

Example
let user='Nishant Kumar';
let city='Pune';
//[Link](`Hello ${user} you stay in ${city}`);
//[Link](`Hello "${user}" you stay in "${city}"`);
//[Link](`Hello '${user}' you stay in '${city}'`);

let allin1=`Hello
${user}
you stay in
${city}`;
[Link](allin1);
Example 2 : How to use String literals in function
let firstName='Nishant';
let lastName='kumar';

function fullname(firstName,lastName){

return `${firstName} ${lastName}`;


}
let userDetail=`Hello ${fullname(firstName,lastName)}`;
[Link](userDetail);

You might also like