What are strings?

Strings are text data - letters, numbers, symbols, and spaces wrapped in quotes. They’re one of the most common data types you’ll use when working with user input, messages, and game data.

Benefits of using strings?

const playerName = "Astro";
const message = "Welcome to the game!";
const greeting = 'Hello!';

// String concatenation
const fullMessage = playerName + " says: " + message;
console.log(fullMessage);

// String properties
console.log(playerName.length); // 5
console.log(message.toUpperCase()); // WELCOME TO THE GAME!
console.log(message.toLowerCase()); // welcome to the game!
console.log(message.includes("game")); // true
console.log(message.charAt(0)); // W

// Template literals
const levelName = "Alien Planet";
const description = `You are on the ${levelName}. Stay alert!`;
console.log(description);

What does this code do?

Try It Yourself

%%js // CODE_RUNNER: strings const message = “Welcome to the Game”; console.log(message.length); console.log(message.toUpperCase()); console.log(message.substring(0, 7)); console.log(message.includes(“Game”));