28 December, 2023
String Interpolation & Template Literals
is string interpolation and Template Literals is same ? yes absolutely correct. In JavaScript, string interpolation and template literals refer to the same concept.
- Template Literals:
- Template literals are a type of string literal in JavaScript, created using backticks (` ` ).
- They allow you to embed expressions or variables inside the string using
${}
syntax.
let name = "arnob";
let greeting = `Hello, ${name}!`;
output will be
Hello, arnob!
- String Interpolation:
- String interpolation is the process of evaluating and inserting expressions or variables into a string.
- In JavaScript, template literals are commonly used for string interpolation.
let friend = "arnob";
let sentence = `Hey, ${friend}! How's it going?`;
output will be Hey, arnob! How's it going?
javascript
coding
programming
intermediate