Skip to content
dreamcode
dreamcode
Map
Strings
Lesson 3 of 48
+15 XP on finish
JS BASICSChapter 1 · JS Basics

Strings and Template Literals

Wrap text in backticks to make a template literal: anything inside ${...} is worked out and dropped into the string. Strings also come with methods: .toUpperCase(), .trim(), .includes(), .split(), .replace(), and the .length property counts characters. String methods return a new string; the original never changes.

Worked example

How it reads

  • Backticks plus ${...} drop values straight into text
  • .trim() removes spaces from both ends
  • .split(" ") breaks text into an array of words
Common mistakes
  • Using normal quotes with ${name} prints the braces literally. Only backticks switch them on.
Cloud tip: Template literals can span several lines, which makes them handy for longer messages.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Use a template literal to print exactly Mars has 2 moons, using both variables.

Press Run to check your work.