Beginner · 8 min
Build a message
Combine text with values and use common string methods.
Join text and values
The + operator can join strings. When one side is a string, the other value is converted to text. Use spaces inside your strings where needed.
const name = "Ada";
console.log("Hello, " + name + "!");Output
Hello, Ada!
Clean up text
trim() removes whitespace from both ends of a string. toLowerCase() returns a lowercase version. String methods return new strings; they do not change the original.
const city = " PARIS ";
const cleaned = city.trim().toLowerCase();
console.log(cleaned);Output
paris
Put it into practice
- Predict the output of each example before running it.
- Complete the coding task, then try the practice questions.
Try it yourself
Code runs on this device. When you are signed in, drafts sync to your account.
Make a welcome message
Set message to "Welcome, Mina!" using name, then display message.
Join "Welcome, ", name, and "!" with +.