mozilla

Revision 17771 of typeof

  • Revision slug: JavaScript/Reference/Operators/typeof
  • Revision title: typeof
  • Revision id: 17771
  • Created:
  • Creator: Mgjbot
  • Is current revision? No
  • Comment robot Adding: [[fr:Référence de JavaScript 1.5 Core:Opérateurs:Opérateurs spéciaux:L'opérateur typeof]] <<langbot>>

Revision Content

Summary

The typeof operator is used in either of the following ways:

  1. typeof operand
  2. typeof (operand)

The typeof operator returns a string indicating the type of the unevaluated operand. operand is the string, variable, keyword, or object for which the type is to be returned. The parentheses are optional.

Operator
Implemented in: JavaScript 1.1
ECMA Version: ECMA-262

Suppose you define the following variables:

var myFun = new Function("5+2")
var shape="round"
var size=1
var today=new Date()

The typeof operator returns the following results for these variables:

typeof myFun is object
typeof shape is string
typeof size is number
typeof today is object
typeof dontExist is undefined

For the keywords true and null, the typeof operator returns the following results:

typeof true is boolean
typeof null is object

For a number or string, the typeof operator returns the following results:

typeof 62 is number
typeof 'Hello world' is string

For property values, the typeof operator returns the type of value the property contains:

typeof document.lastModified is string
typeof window.length is number
typeof Math.LN2 is number

For methods and functions, the typeof operator returns results as follows:

typeof blur is function
typeof eval is function
typeof parseInt is function
typeof shape.split is function

For predefined objects, the typeof operator returns results as follows:

typeof Date is function
typeof Function is function
typeof Math is function
typeof Object is function
typeof String is function
{{ wiki.languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Op\u00e9rateurs/Op\u00e9rateurs_sp\u00e9ciaux/L\'op\u00e9rateur_typeof", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Operatory/Operatory_specjalne/Operator_typeof" } ) }}

Revision Source

<p>
</p>
<h3 name="Summary"> Summary </h3>
<p>The <code>typeof</code> operator is used in either of the following ways:
</p>
<ol><li> <code>typeof <i>operand</i></code>
</li><li> <code>typeof (<i>operand</i>)</code>
</li></ol>
<p>The <code>typeof</code> operator returns a string indicating the type of the unevaluated operand. <code>operand</code> is the string, variable, keyword, or object for which the type is to be returned. The parentheses are optional.
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2">Operator</td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.1</td>
</tr>
<tr>
<td>ECMA Version:</td>
<td>ECMA-262</td>
</tr>
</tbody></table>
<p>Suppose you define the following variables:
</p>
<pre>var myFun = new Function("5+2")
var shape="round"
var size=1
var today=new Date()
</pre>
<p>The <code>typeof</code> operator returns the following results for these variables:
</p>
<pre>typeof myFun is object
typeof shape is string
typeof size is number
typeof today is object
typeof dontExist is undefined
</pre>
<p>For the keywords <code>true</code> and <code>null</code>, the <code>typeof</code> operator returns the following results:
</p>
<pre>typeof true is boolean
typeof null is object
</pre>
<p>For a number or string, the <code>typeof</code> operator returns the following results:
</p>
<pre>typeof 62 is number
typeof 'Hello world' is string
</pre>
<p>For property values, the <code>typeof</code> operator returns the type of value the property contains:
</p>
<pre>typeof document.lastModified is string
typeof window.length is number
typeof Math.LN2 is number
</pre>
<p>For methods and functions, the <code>typeof</code> operator returns results as follows:
</p>
<pre>typeof blur is function
typeof eval is function
typeof parseInt is function
typeof shape.split is function
</pre>
<p>For predefined objects, the <code>typeof</code> operator returns results as follows:
</p>
<pre>typeof Date is function
typeof Function is function
typeof Math is function
typeof Object is function
typeof String is function
</pre>
<div class="noinclude">
</div>
{{ wiki.languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Op\u00e9rateurs/Op\u00e9rateurs_sp\u00e9ciaux/L\'op\u00e9rateur_typeof", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Operatory/Operatory_specjalne/Operator_typeof" } ) }}
Revert to this revision