Challenge - 5 Problems
Type Checking Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of typeof with different values
What is the output of the following code snippet?
Javascript
console.log(typeof null);
Attempts:
2 left
💡 Hint
Remember that typeof null is a known quirk in JavaScript.
✗ Incorrect
In JavaScript, typeof null returns "object" due to legacy reasons.
❓ Predict Output
intermediate2:00remaining
Type of an array using typeof
What will be the output of this code?
Javascript
console.log(typeof [1, 2, 3]);
Attempts:
2 left
💡 Hint
Arrays are a special kind of object in JavaScript.
✗ Incorrect
The typeof operator returns "object" for arrays because arrays are objects in JavaScript.
❓ Predict Output
advanced2:00remaining
Output of typeof with function and symbol
What is the output of this code snippet?
Javascript
console.log(typeof function() {}); console.log(typeof Symbol('id'));
Attempts:
2 left
💡 Hint
Functions have their own type, and symbols are a unique primitive type.
✗ Incorrect
The typeof operator returns "function" for functions and "symbol" for symbols.
❓ Predict Output
advanced2:00remaining
Type of NaN using typeof
What will this code output?
Javascript
console.log(typeof NaN);
Attempts:
2 left
💡 Hint
NaN stands for Not-a-Number but is still a number type in JavaScript.
✗ Incorrect
Despite its name, NaN is of type "number" in JavaScript.
❓ Predict Output
expert2:00remaining
Type checking with typeof and undefined variables
What is the output of this code?
Javascript
let a; console.log(typeof a); console.log(typeof b);
Attempts:
2 left
💡 Hint
typeof returns "undefined" for both declared but unassigned variables and undeclared variables without throwing errors.
✗ Incorrect
Variable a is declared but not assigned, so typeof a returns "undefined". Variable b is undeclared, but typeof b also returns "undefined" safely without throwing a ReferenceError.