typeof Operator, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
typeof Operator in one minute
What students need to know
typeof is exactly the operator used to check a value's type. typeof true returns the string "boolean".
JavaScript is case-sensitive, so 'typeof' must be lowercase. typeof works on both variables and literal values.
Mistakes students make
- The operator is 'typeof', not just 'type'.
- 'typeof' must be lowercase - a capital T causes an error.
- This line is actually correct - typeof can be used with or without parentheses.
- Missing space between 'typeof' and the variable name.
PREVIOUS · MODULE 8Template Literals
YOU ARE HERE · MODULE 9typeof Operator
NEXT · MODULE 10Type Conversion
What students will learn in this module
Every question in Module 9
Quick questions
- Does typeof return a string naming a value's data type?AYesBNo
- Is 'type' by itself a valid JavaScript operator?AYesBNo
- Must 'typeof' be written in lowercase?AYesBNo
- Can typeof be used on a variable or a direct value like 42?AYesBNo
- Does typeof true return "boolean"?ANoBYes
Key terms
Students type the meaning of:
typeof
Match the pairs
typeof "hello"Match it to what it doestypeof 42Match it to what it doesChecks the data type of a valueMatch it to what it doesReturns a string naming a boolean's typeMatch it to what it doesconsole.log(Typeof name);Match it to what it doesconsole.log(type age);Match it to what it doesFill in the blanks
console.log(______ name);
Hint: Type the operator that returns a value's data type.
console.log(______ age);
Hint: Type the operator that returns a value's data type.
let result = ______ isReady;
Hint: Type the operator that returns a value's data type.
console.log(______ 42);
Hint: Type the operator that returns a value's data type.
let kind = ______ "hi";
Hint: Type the operator that returns a value's data type.
Spot the error
Question 1
Alet x = 5;Bconsole.log(type x);Clet y = true;
Question 2
Aconsole.log(Typeof name);Blet name = "Amy";Clet age = 10;
Question 3
Alet flag = true;Bconsole.log(typeof(flag));Cconsole.log(typeof flag);
Question 4
Aconsole.log(typeofn);Blet n = 5;Cconsole.log(typeof n);
Question 5
Alet s = "hi";Bconsole.log(typeof s);Cconsole.log(typof s);
