Strings support using embedded expressions (variables such as objects, arrays, numbers and more) within them.
1. The + operator
let firstName = "John"; let age = 30; let message = "Hello, " + firstName + ". You are " + age + " years old."; message;//Hello, John. You are 30 years old.
2. Template Strings
To convert a regular string to a template string, you need to use backticks (`) around the string instead of double quotation marks (“”) and add any expression with the ${}` within a template string.
let firstName = "John"; let age = 30; let message = `Hello, ${firstName.toUpperCase()}. You are ${age} years old.`; message;//Hello, JOHN. You are 30 years old.
Here are few problems where these concepts are used:
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article