0
0
Javascriptprogramming~5 mins

Type checking using typeof in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the typeof operator do in JavaScript?
It tells you the type of a value or variable, like whether it is a number, string, boolean, object, function, or undefined.
Click to reveal answer
beginner
What is the result of typeof 42?
The result is "number" because 42 is a number.
Click to reveal answer
intermediate
What does typeof null return and why is it special?
It returns "object". This is a known quirk in JavaScript where null is considered an object type even though it means 'no value'.
Click to reveal answer
beginner
How can you check if a variable is a function using typeof?
Use typeof variable === 'function'. This returns true if the variable holds a function.
Click to reveal answer
intermediate
What type does typeof return for arrays?
It returns "object" because arrays are a special kind of object in JavaScript.
Click to reveal answer
What will typeof 'hello' return?
A"string"
B"text"
C"char"
D"object"
Which typeof result means the variable is not defined or has no value?
A"null"
B"undefined"
C"void"
D"none"
What does typeof function() {} return?
A"method"
B"object"
C"function"
D"callable"
What is the typeof result for an array like []?
A"object"
B"collection"
C"list"
D"array"
Why is typeof null considered a quirk?
ABecause it returns "undefined"
BBecause it throws an error
CBecause it returns "null"
DBecause it returns "object"
Explain how the typeof operator helps in checking variable types in JavaScript.
Think about how you can tell what kind of value a variable holds.
You got /3 concepts.
    Describe the special case of typeof null and why it might confuse beginners.
    Consider what null means and what typeof returns.
    You got /3 concepts.