String Concatenation

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

This String Concatenation worksheet is part of the JavaScript Coding without HTML and CSS journey. Print it as a booklet?

String Concatenation

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

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

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1"Hi " + name AWrong - concatenation uses +, not -
2first + " " + last BJoins first, a space, and last into one string
3Combines two strings into one using + Cgreeting + "!"
4Joins a string literal with a variable's value D"Age: " + age
5let msg = "Hi " - name; EWrong - only one + is needed to join two values
6let z = x + + y; FJoins the string "Hi " with the value of name

Definitions

+

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let msg = "Hi " _ name;
2.
let full = firstName _ lastName;
3.
let years = "Age: " _ age;
4.
let combo = a _ b + c;
5.
let msg2 = greeting _ "!";

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let msg = "Hi " - name;
B console.log(msg);
C let x = 1;
Question 2
A let a = "Hello";
B let b = a "World";
C console.log(b);
Question 3
A let x = "A";
B let y = "B";
C let z = x + + y;
Question 4
A let first = "Sam";
B let last = "Lee";
C let full = first + last;
D let full2 = first * last;
Question 5
A let name = "Amy";
B let msg = "Hi " + name;
C console.log(msg);
D let x = 1;
E let bad = Hi + name;

Answer Key

String Concatenation
Section A: Quick Questions
Q1
A — Yes
Q2
B — No
Q3
A — Yes
Q4
B — Yes
Q5
A — No
Section B: Match the Pairs
Q1
"Hi " + name → Joins the string "Hi " with the value of name
Q2
first + " " + last → Joins first, a space, and last into one string
Q3
Combines two strings into one using + → greeting + "!"
Q4
Joins a string literal with a variable's value → "Age: " + age
Q5
let msg = "Hi " - name; → Wrong - concatenation uses +, not -
Q6
let z = x + + y; → Wrong - only one + is needed to join two values
Section C: Definitions
Q1
+ — Joins two strings together into one when used between them.
Section D: Fill in the Blanks
Q1
let msg = "Hi " + name;
Q2
let full = firstName + lastName;
Q3
let years = "Age: " + age;
Q4
let combo = a + b + c;
Q5
let msg2 = greeting + "!";
Section E: Spot the Error
Q1
A — Concatenation uses +, not -, to join strings.
Q2
B — Missing + between the two strings being joined.
Q3
C — Extra + causes invalid syntax - only one + is needed.
Q4
D — Concatenation uses +, not *, to join strings.
Q5
E — The string "Hi " needs quotes, or Hi is read as a variable.