Checking a data type
Programs often deal with information where some data types are unknown. For example, with JSON.parse
, the value produced from the transformation depends on the input string which usually comes from an external source.
The typeof
operator produces a string that indicates a value's data type.
Loading TypeScript...
Notice that typeof undefined
produces the string "undefined"
, but typeof null
produces the string "object"
. This is actually the expected behavior!
Loading TypeScript...