Use backticks (
const name = 'John';
const greeting = `Hello, ${name}!`;
const multilineString = `This is a
multiline
string.`;
Insert variables or expressions into strings using
const age = 25;
const message = `I am ${age} years old.`;
Use the logical OR (
const username = userInput || 'Guest';
Take advantage of various string methods for common operations.
const text = 'Hello, World!';
const uppercase = text.toUpperCase();
const lowercase = text.toLowerCase();
const substring = text.substring(0, 5);
const replaced = text.replace('World', 'JavaScript');