0
0
Javascriptprogramming~10 mins

Type checking using typeof in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check the type of variable value.

Javascript
console.log(typeof [1]);
Drag options to blanks, or click blank then click option'
Avalue
B"value"
Ctypeof value
Dtypeof
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable name inside quotes, which makes it a string literal.
Using typeof inside typeof like a function call.
2fill in blank
medium

Complete the code to check if input is a string.

Javascript
if (typeof input === [1]) {
  console.log("It's a string!");
}
Drag options to blanks, or click blank then click option'
Astring
B"string"
C'string'
D"String"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the type name without quotes, causing a ReferenceError.
Using uppercase letters in the type string.
3fill in blank
hard

Fix the error in the code to correctly check if num is a number.

Javascript
if (typeof num === [1]) {
  console.log("It's a number!");
}
Drag options to blanks, or click blank then click option'
A"number"
B== "number"
C=== "number"
D"Number"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single equals sign = instead of ===.
Using uppercase letters in the type string.
4fill in blank
hard

Fill both blanks to create an object with keys as variable names and values as their types.

Javascript
const types = {
  name: [1],
  age: [2]
};
Drag options to blanks, or click blank then click option'
Atypeof name
Btypeof age
C"string"
D"number"
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the typeof expressions, making them strings.
Using the type strings directly instead of typeof expressions.
5fill in blank
hard

Fill all three blanks to create a function that returns true if val is a boolean.

Javascript
function isBoolean(val) {
  return typeof [1] [2] [3];
}
Drag options to blanks, or click blank then click option'
Aval
B===
C"boolean"
Dval === "boolean"
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment = instead of comparison ===.
Comparing to boolean without quotes.
Putting the whole expression inside quotes.