String Concatenation, online

Six activities your students do on their own devices. See who's finished, and their scores.

String Concatenation in one minute

What students need to know

This code appends "!" to the end of greeting. This concatenates the text "Age: " with the age variable.

+ joins strings into a single combined string. Concatenation always uses +, never -.

Mistakes students make

  • Concatenation uses +, not -, to join strings.
  • Missing + between the two strings being joined.
  • Extra + causes invalid syntax - only one + is needed.
  • Concatenation uses +, not *, to join strings.

Discover other journeys with this module

What students will learn in this module

Every question in Module 7

Quick questions

  1. Does + join two strings together in JavaScript?AYesBNo
  2. Is - used to join two strings together?AYesBNo
  3. Does leaving out + between two strings cause an error?AYesBNo
  4. Can you concatenate a string literal with a variable?ANoBYes
  5. Is a + + b valid syntax for joining two strings?ANoBYes

Key terms

Students type the meaning of:

  • +

Match the pairs

"Hi " + nameMatch it to what it does
first + " " + lastMatch it to what it does
Combines two strings into one using +Match it to what it does
Joins a string literal with a variable's valueMatch it to what it does
let msg = "Hi " - name;Match it to what it does
let z = x + + y;Match it to what it does

Fill in the blanks

  1. let msg = "Hi " _ name;

    Hint: Type the operator that joins two strings together.

  2. let full = firstName _ lastName;

    Hint: Type the operator that joins two strings together.

  3. let years = "Age: " _ age;

    Hint: Type the operator that joins two strings together.

  4. let combo = a _ b + c;

    Hint: Type the operator that joins two strings together.

  5. let msg2 = greeting _ "!";

    Hint: Type the operator that joins two strings together.

Spot the error

Question 1

Alet msg = "Hi " - name;Bconsole.log(msg);Clet x = 1;

Question 2

Alet a = "Hello";Blet b = a "World";Cconsole.log(b);

Question 3

Alet x = "A";Blet y = "B";Clet z = x + + y;

Question 4

Alet first = "Sam";Blet last = "Lee";Clet full = first + last;Dlet full2 = first * last;

Question 5

Alet name = "Amy";Blet msg = "Hi " + name;Cconsole.log(msg);Dlet x = 1;Elet bad = Hi + name;