Operators and strings · Lesson 7 of 45
Strings and template literals
Write text and drop variables into it easily.
7 minutes3 games
Text goes between "...", '...' or ` ... (backticks). The third, a **template literal**, is the most powerful: put any value inside ${...}` and write across several lines.
JavaScript
const name = "Laila"
const lessons = 7
console.log(`${name} finished ${lessons} lessons`)
console.log(`Next week: ${lessons + 3}`)
console.log("Old way: " + name + " finished " + lessons)
const card = `Name: ${name}
Level: ${lessons > 5 ? "Advanced" : "Beginner"}`
console.log(card)"SeaCode" =
S[0]
e[1]
a[2]
C[3]
o[4]
d[5]
e[6]
Each character has an index starting at 0. word[0] is S and word.length is 7.
JavaScript
const word = "SeaCode" console.log(word.length) // 7 console.log(word[0]) // S console.log(word.at(-1)) // e: last character console.log(word[10]) // undefined
Complete the code
Complete it so it prints Hi Sara.
const user = "Sara" console.log(`Hi `)
What's the output?
console.log("code".length)What will this code print?
Exercise
Print Total: 60 EGP with a template literal and the two variables.
Expected output: Total: 60 EGP
JavaScript
const price = 20 const qty = 3
Learn more from
Played 0 of 3 games
Sign in to save your progress and earn XP.