UNPKG

3.77 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function typeOf
4
5Determine the type of a variable.
6
7Function `typeOf` recognizes the following types of objects:
8
9Object | Returns | Example
10---------------------- | ------------- | ------------------------------------------
11null | `'null'` | `math.typeOf(null)`
12number | `'number'` | `math.typeOf(3.5)`
13boolean | `'boolean'` | `math.typeOf(true)`
14string | `'string'` | `math.typeOf('hello world')`
15Array | `'Array'` | `math.typeOf([1, 2, 3])`
16Date | `'Date'` | `math.typeOf(new Date())`
17Function | `'Function'` | `math.typeOf(function () {})`
18Object | `'Object'` | `math.typeOf({a: 2, b: 3})`
19RegExp | `'RegExp'` | `math.typeOf(/a regexp/)`
20undefined | `'undefined'` | `math.typeOf(undefined)`
21math.BigNumber | `'BigNumber'` | `math.typeOf(math.bignumber('2.3e500'))`
22math.Chain | `'Chain'` | `math.typeOf(math.chain(2))`
23math.Complex | `'Complex'` | `math.typeOf(math.complex(2, 3))`
24math.Fraction | `'Fraction'` | `math.typeOf(math.fraction(1, 3))`
25math.Help | `'Help'` | `math.typeOf(math.help('sqrt'))`
26math.Help | `'Help'` | `math.typeOf(math.help('sqrt'))`
27math.Index | `'Index'` | `math.typeOf(math.index(1, 3))`
28math.Matrix | `'Matrix'` | `math.typeOf(math.matrix([[1,2], [3, 4]]))`
29math.Range | `'Range'` | `math.typeOf(math.range(0, 10))`
30math.ResultSet | `'ResultSet'` | `math.typeOf(math.evaluate('a=2\nb=3'))`
31math.Unit | `'Unit'` | `math.typeOf(math.unit('45 deg'))`
32math.AccessorNode | `'AccessorNode'` | `math.typeOf(math.parse('A[2]'))`
33math.ArrayNode | `'ArrayNode'` | `math.typeOf(math.parse('[1,2,3]'))`
34math.AssignmentNode | `'AssignmentNode'` | `math.typeOf(math.parse('x=2'))`
35math.BlockNode | `'BlockNode'` | `math.typeOf(math.parse('a=2; b=3'))`
36math.ConditionalNode | `'ConditionalNode'` | `math.typeOf(math.parse('x<0 ? -x : x'))`
37math.ConstantNode | `'ConstantNode'` | `math.typeOf(math.parse('2.3'))`
38math.FunctionAssignmentNode | `'FunctionAssignmentNode'` | `math.typeOf(math.parse('f(x)=x^2'))`
39math.FunctionNode | `'FunctionNode'` | `math.typeOf(math.parse('sqrt(4)'))`
40math.IndexNode | `'IndexNode'` | `math.typeOf(math.parse('A[2]').index)`
41math.ObjectNode | `'ObjectNode'` | `math.typeOf(math.parse('{a:2}'))`
42math.ParenthesisNode | `'ParenthesisNode'` | `math.typeOf(math.parse('(2+3)'))`
43math.RangeNode | `'RangeNode'` | `math.typeOf(math.parse('1:10'))`
44math.SymbolNode | `'SymbolNode'` | `math.typeOf(math.parse('x'))`
45
46
47## Syntax
48
49```js
50math.typeOf(x)
51```
52
53### Parameters
54
55Parameter | Type | Description
56--------- | ---- | -----------
57`x` | * | The variable for which to test the type.
58
59### Returns
60
61Type | Description
62---- | -----------
63string | Returns the name of the type. Primitive types are lower case, non-primitive types are upper-camel-case. For example 'number', 'string', 'Array', 'Date'.
64
65
66## Examples
67
68```js
69math.typeOf(3.5) // returns 'number'
70math.typeOf(math.complex('2-4i')) // returns 'Complex'
71math.typeOf(math.unit('45 deg')) // returns 'Unit'
72math.typeOf('hello world') // returns 'string'
73```
74
75