xxxxxxxxxx
//
const firstName = 'john';
const lastName = 'smith';
const output = `name: ${firstName}, surname: ${lastName}`;
// name: john, surname: smith
xxxxxxxxxx
const string = 'This is a string.';
const message = `${string} This is also a string.`;
xxxxxxxxxx
let name = "John";
let age = 30;
let food = "pizza";
// String formating using backticks
let sentence = `${name} is ${age} years old and likes ${food}`;
console.log(sentence);
// John is 30 years old and likes pizza
// String formating using plus operator
let sentence = name + ' is ' + age + ' years old and likes ' + food;
console.log(sentence); // John is 30 years old and likes pizza
xxxxxxxxxx
let name = "John";
let age = 30;
let food = "pizza";
// String formating using backticks
let sentence = `${name} is ${age} years old and likes ${food}`;
console.log(sentence); // John is 30 years old and likes pizza
xxxxxxxxxx
const name = 'Alice';
const age = 28;
const message = `My name is ${name} and I am ${age} years old.`;
console.log(message); // Output: My name is Alice and I am 28 years old.
xxxxxxxxxx
const name = 'Alice';
const age = 25;
const formattedString = `My name is ${name} and I am ${age} years old.`;
console.log(formattedString);
xxxxxxxxxx
const firstString = '2 + 2'; // Creates a string literal value
const secondString = new String('2 + 2'); // Creates a String object
eval(firstString); // Returns the number 4
eval(secondString); // Returns a String object containing "2 + 2"