Returns a string that identifies the data type of an expression.
Syntaxtypeof [ ( ] expression [ ) ] ;
Examples
The following example tests the data type of variables.
var index = 5;
var result = (typeof index === 'number');
var description = "abc";
var result = (typeof description === 'string');
The following example tests for a data type of undefined for declared and undeclared variables.
var declared;
var result = (declared === undefined);
var result = (typeof declared === 'undefined');
var result = (typeof notDeclared === 'undefined')
var obj = {};
var result = (typeof obj.propNotDeclared === 'undefined');
Remarks
The expression argument is any expression for which type information is sought.
The typeof operator returns type information as a string. There are six possible values that typeof returns: “number,” “string,” “boolean,” “object,” “function,” and “undefined.”
The parentheses are optional in the typeof syntax.
See also Other articles AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4