Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.4 — Strings Basics
JavaScript · Example 2 of 4 ES2015+

Template literals

${ } only works inside backticks. In normal quotes it's ordinary text.

A string is text: a fixed sequence of characters in quotes. You can write it three ways, escape special characters, insert values with template literals, read its length and single characters, but never change it in place.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Store a city and a temperature in variables and log It is 31°C in Pune today. using a template literal.

02

Log the first and last character of any word you choose, without typing the index of the last character by hand.

03

Log a two-line address with a single console.log call.

Explain it without notes

01

What is the difference between single quotes, double quotes and backticks?

02

What does it mean that strings are immutable? Give an example.

03

Why is "😀".length equal to 2?

Template literals ES2015+

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Hi Asha, your 3 items cost ₹750.
Roses are red,
Violets are blue
Is the cart big? false
Not in backticks: ${name}