The typeof Operator
typeof is an operator that produces a string describing the broad type of a value. It does not fully identify every kind of object.
Ask JavaScript what kind of value it sees before deciding how to handle it.
See the mechanism
"4"Follow one example
The first two outputs differ because quoted text and a numeric value have different types. typeof null is "object", a historical quirk; it does not mean null is an object you can access. Test null directly when that distinction matters.
Predict, change and check
Predict: Will typeof "false" report boolean or string? Why?
Test your explanation: Add console.log(typeof "false"). Then remove the quotes and compare. Do not use typeof alone to detect null.
The tasks below ask you to explain that result and apply the idea to different inputs.
Apply and distinguish
Use typeof for its actual granularity
typeof distinguishes broad categories, not every useful application type. Arrays, dates and null all need more specific checks than the string 'object'. Array.isArray is appropriate for an array boundary; typeof value === 'object' must also exclude null when a non-null object is required.
typeof an absent identifier can return 'undefined' without reading a property on it, but a lexical binding in its temporal dead zone can still throw. Do not use a typeof test alone as complete schema validation. For example, a string title can still violate an application's empty-title policy, and a number can be NaN or infinite.
Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.