Home > Article > Web Front-end > How to use typeof in js
typeof operator returns the type of operand, its syntax is: typeof operand. It returns one of the following string types: "undefined", "null", "boolean", "number", "bigint", "string", "symbol", or "object". Returning null "object" is a historical issue. Composite data structure
Usage of typeof operator in JavaScript
# The ##typeof operator is a unary operator that returns a string indicating the type of the operand.Syntax:
<code>typeof operand</code>
Parameters:
: To determine its type expression or variable.
Return value:
A string representing the type ofoperand:
: The value is undefined.
: The value is
null.
: The value is a Boolean value.
: The value is a number.
: The value is a big integer.
: The value is a string.
: The value is a Symbol value.
: The value is an object, including functions, arrays and regular expressions.
Example:
<code class="js">console.log(typeof undefined); // "undefined" console.log(typeof null); // "object" console.log(typeof true); // "boolean" console.log(typeof 123); // "number" console.log(typeof "Hello World"); // "string" console.log(typeof Symbol("Symbol")); // "symbol" console.log(typeof [1, 2, 3]); // "object" console.log(typeof function() {}); // "function"</code>
Note: The
Returning
"object" is a historical issue. It should return
"null", but this cannot be changed due to backward compatibility.
is a composite data structure, such as an array or object, the typeof operator will return
"object".
The above is the detailed content of How to use typeof in js. For more information, please follow other related articles on the PHP Chinese website!