patternjavascriptCritical
String interpolation in JavaScript?
Viewed 0 times
stringjavascriptinterpolation
Problem
Consider this code:
Are there any other ways to insert the value of a variable in to a string, apart from string concatenation?
var age = 3;
console.log("I'm " + age + " years old!");Are there any other ways to insert the value of a variable in to a string, apart from string concatenation?
Solution
Since ES6, you can use template literals:
P.S. Note the use of backticks: ````.
const age = 3
console.log(I'm ${age} years old!)
P.S. Note the use of backticks: ````.
Context
Stack Overflow Q#1408289, score: 1017
Revisions (0)
No revisions yet.