typeof Operator

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

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

typeof Operator

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does typeof return a string naming a value's data type?
A Yes
B No
2. Is 'type' by itself a valid JavaScript operator?
A Yes
B No
3. Must 'typeof' be written in lowercase?
A Yes
B No
4. Can typeof be used on a variable or a direct value like 42?
A Yes
B No
5. Does typeof true return "boolean"?
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
1typeof "hello" Atypeof true
2typeof 42 BWrong - the full operator is 'typeof', not 'type'
3Checks the data type of a value Ctypeof
4Returns a string naming a boolean's type DReturns "string"
5console.log(Typeof name); EWrong - 'typeof' must be lowercase
6console.log(type age); FReturns "number"

Definitions

typeof

Fill in the Blanks

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

1.
console.log(______ name);
2.
console.log(______ age);
3.
let result = ______ isReady;
4.
console.log(______ 42);
5.
let kind = ______ "hi";

Spot the Error

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

Question 1
A let x = 5;
B console.log(type x);
C let y = true;
Question 2
A console.log(Typeof name);
B let name = "Amy";
C let age = 10;
Question 3
A let flag = true;
B console.log(typeof(flag));
C console.log(typeof flag);
Question 4
A console.log(typeofn);
B let n = 5;
C console.log(typeof n);
Question 5
A let s = "hi";
B console.log(typeof s);
C console.log(typof s);

Answer Key

typeof Operator
Section A: Quick Questions
Q1
A — Yes
Q2
B — No
Q3
A — Yes
Q4
A — Yes
Q5
B — Yes
Section B: Match the Pairs
Q1
typeof "hello" → Returns "string"
Q2
typeof 42 → Returns "number"
Q3
Checks the data type of a value → typeof
Q4
Returns a string naming a boolean's type → typeof true
Q5
console.log(Typeof name); → Wrong - 'typeof' must be lowercase
Q6
console.log(type age); → Wrong - the full operator is 'typeof', not 'type'
Section C: Definitions
Q1
typeof — An operator that returns a string naming the data type of a value.
Section D: Fill in the Blanks
Q1
console.log(typeof name);
Q2
console.log(typeof age);
Q3
let result = typeof isReady;
Q4
console.log(typeof 42);
Q5
let kind = typeof "hi";
Section E: Spot the Error
Q1
B — The operator is 'typeof', not just 'type'.
Q2
A — 'typeof' must be lowercase - a capital T causes an error.
Q3
B — This line is actually correct - typeof can be used with or without parentheses.
Q4
A — Missing space between 'typeof' and the variable name.
Q5
C — 'typeof' is misspelled as 'typof'.