Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda String Manipulation Techniques | Understanding JavaScript Data Types
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

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 4

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Awesome!

Completion rate improved to 6.25

bookString Manipulation Techniques

Deslize para mostrar o 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

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 4
some-alt