Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn String Manipulation Techniques | Understanding JavaScript Data Types
Quizzes & Challenges
Quizzes
Challenges
/
JavaScript Data Types Foundations

bookString Manipulation Techniques

1234567891011121314151617
// String concatenation const firstName = "Alex"; const greeting1 = "Hello, " + firstName + "!"; // Template literal const greeting2 = `Hello, ${firstName}!`; // Using string methods const shout = greeting2.toUpperCase(); const hasHello = greeting2.includes("Hello"); const messageLength = greeting2.length; console.log(greeting1); // Hello, Alex! console.log(greeting2); // Hello, Alex! console.log(shout); // HELLO, ALEX! console.log(hasHello); // true console.log(messageLength); // 12
copy

When working with strings in JavaScript, you often need to combine, inspect, or modify them. You have seen two primary ways to build a greeting message: string concatenation using the + operator, and template literals using backticks and ${} for embedding variables. Template literals make it easier to include variables and expressions directly in strings.

Beyond building strings, you can use several helpful string methods. The length property tells you how many characters are in a string, including spaces and punctuation. The toUpperCase() method returns a new string with all letters converted to uppercase, which is useful for standardizing text. The includes() method checks if a substring exists within a string, returning true or false. For example, greeting2.includes("Hello") checks if "Hello" is part of the greeting message.

Combining these techniques allows you to construct and analyze strings efficiently, which is essential for tasks like formatting output, validating input, or searching within text.

question mark

Which of the following statements about the code above are correct?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 6.25

bookString Manipulation Techniques

Swipe to show menu

1234567891011121314151617
// String concatenation const firstName = "Alex"; const greeting1 = "Hello, " + firstName + "!"; // Template literal const greeting2 = `Hello, ${firstName}!`; // Using string methods const shout = greeting2.toUpperCase(); const hasHello = greeting2.includes("Hello"); const messageLength = greeting2.length; console.log(greeting1); // Hello, Alex! console.log(greeting2); // Hello, Alex! console.log(shout); // HELLO, ALEX! console.log(hasHello); // true console.log(messageLength); // 12
copy

When working with strings in JavaScript, you often need to combine, inspect, or modify them. You have seen two primary ways to build a greeting message: string concatenation using the + operator, and template literals using backticks and ${} for embedding variables. Template literals make it easier to include variables and expressions directly in strings.

Beyond building strings, you can use several helpful string methods. The length property tells you how many characters are in a string, including spaces and punctuation. The toUpperCase() method returns a new string with all letters converted to uppercase, which is useful for standardizing text. The includes() method checks if a substring exists within a string, returning true or false. For example, greeting2.includes("Hello") checks if "Hello" is part of the greeting message.

Combining these techniques allows you to construct and analyze strings efficiently, which is essential for tasks like formatting output, validating input, or searching within text.

question mark

Which of the following statements about the code above are correct?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4
some-alt