正解:A
This question focuses on the typeof operator and how JavaScript represents the type of the value null.
* Declaration on line 1:
let x = null;
Here:
* x is explicitly assigned the value null.
* In JavaScript, null is a special primitive value that represents "no value" or "empty value".
* Line 2:
console.log(typeof x);
The typeof operator returns a string indicating the type of the operand. For example:
* typeof 1 returns " number "
* typeof " hello " returns " string "
* typeof true returns " boolean "
* typeof undefined returns " undefined "
* typeof {} returns " object "
* typeof [] returns " object " (arrays are objects)
* typeof function() {} returns " function "
For null, due to an early design decision in JavaScript, the result is:
typeof null === " object "
This is a known historical quirk of the language:
* Although null is a primitive and conceptually means "no object", typeof null returns the string " object "
.
Therefore, typeof x when x is null evaluates to " object " .
So on line 2, the value printed is:
" object "
This matches option A.
The incorrect options are:
* B. " undefined " : would be typeof x if x were undefined, not null.
* C. " x " : typeof returns a string describing the type of the value, not the variable name.
* D. " null " : although intuitive, JavaScript does not return " null " for typeof null; it returns " object " instead.
Therefore, the correct answer is:
The answer: A
JavaScript knowledge / study guide reference concepts:
* typeof operator and its return values
* Primitive types in JavaScript (null, undefined, number, string, boolean, symbol, bigint)
* Historical behavior: typeof null returning " object "
* Difference between null and undefined in JavaScript