Master JavaScript Data Types: Essential Quiz for Developers
Test your knowledge of JavaScript data types with this comprehensive quiz. From understanding primitives and objects to differentiating between null, undefined, and more, this quiz is designed to strengthen your foundations and help you master JavaScript’s dynamic data types. Perfect for beginners and experienced developers alike!
Question 1.
What is the output of the following code?
A.
null
B.
object
C.
undefined
D.
string
Your Response:
-
Explanation: In JavaScript, typeof null returns "object". This is a historical bug in JavaScript and has remained for compatibility reasons.
Question 2.
Which of the following is a primitive data type in JavaScript?
A.
Object
B.
Array
C.
Symbol
D.
Function
Your Response:
-
Explanation: Primitive data types in JavaScript include string, number, bigint, boolean, undefined, symbol, and null. Objects, arrays, and functions are not primitive.
Question 3.
What will be the result of the following code?
A.
true
B.
false
C.
undefined
D.
Error
Your Response:
-
Explanation: The === operator checks for both value and type. Since x is a number and y is a string, they are not strictly equal.
Question 4.
Which JavaScript type is returned by typeof NaN?
A.
number
B.
NaN
C.
undefined
D.
object
Your Response:
-
Explanation: NaN (Not-a-Number) is a special numeric value that is still of the type number.
Question 5.
Which of these is not a falsy value in JavaScript?
A.
0
B.
"false"
C.
null
D.
undefined
Your Response:
-
Explanation: The string "false" is truthy because it is a non-empty string.
Question 6.
What is the output of the following?
A.
array
B.
object
C.
undefined
D.
function
Your Response:
-
Explanation: In JavaScript, arrays are objects. There is no separate array type.
Question 7.
What does typeof undefined return?
A.
null
B.
undefined
C.
object
D.
string
Your Response:
-
Explanation: The typeof operator returns "undefined" for variables that are declared but not assigned a value.
Question 8.
What will this output?
A.
true
B.
false
C.
undefined
D.
Error
Your Response:
-
Explanation: The == operator performs type coercion, so "5" is converted to a number before comparison.
Question 9.
What is the default type of a variable in JavaScript?
A.
string
B.
undefined
C.
object
D.
null
Your Response:
-
Explanation: In JavaScript, variables are undefined until a value is assigned.
Question 10.
What is the value of typeof function() {}?
A.
function
B.
object
C.
undefined
D.
string
Your Response:
-
Explanation: The typeof operator returns "function" for functions.
Question 11.
Which operator can be used to determine if a variable is an array?
A.
typeof
B.
Array.isArray()
C.
instanceof
D.
Both B and C
Your Response:
-
Explanation: Array.isArray() and instanceof Array can both determine if a value is an array.
Question 12.
What does null mean in JavaScript?
A.
No value
B.
Undefined
C.
An error
D.
An object
Your Response:
-
Explanation: null explicitly represents the absence of any value or object.
Question 13.
What is the result of:
A.
object
B.
undefined
C.
null
D.
function
Your Response:
-
Explanation: In JavaScript, typeof returns "object" for objects.
Question 14.
Which of these will correctly check if x is null?
A.
typeof x === "null"
B.
x === null
C.
x == undefined
D.
typeof x === "undefined"
Your Response:
-
Explanation: null is explicitly checked using strict equality (===).
Question 15.
What is the output?
A.
102
B.
8
C.
"102"
D.
NaN
Your Response:
-
Explanation: The - operator coerces "10" into a number, performing the subtraction.