mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
76 lines (59 loc) • 3.77 kB
Markdown
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function typeOf
Determine the type of a variable.
Function `typeOf` recognizes the following types of objects:
Object | Returns | Example
---------------------- | ------------- | ------------------------------------------
null | `'null'` | `math.typeOf(null)`
number | `'number'` | `math.typeOf(3.5)`
boolean | `'boolean'` | `math.typeOf(true)`
string | `'string'` | `math.typeOf('hello world')`
Array | `'Array'` | `math.typeOf([1, 2, 3])`
Date | `'Date'` | `math.typeOf(new Date())`
Function | `'Function'` | `math.typeOf(function () {})`
Object | `'Object'` | `math.typeOf({a: 2, b: 3})`
RegExp | `'RegExp'` | `math.typeOf(/a regexp/)`
undefined | `'undefined'` | `math.typeOf(undefined)`
math.BigNumber | `'BigNumber'` | `math.typeOf(math.bignumber('2.3e500'))`
math.Chain | `'Chain'` | `math.typeOf(math.chain(2))`
math.Complex | `'Complex'` | `math.typeOf(math.complex(2, 3))`
math.Fraction | `'Fraction'` | `math.typeOf(math.fraction(1, 3))`
math.Help | `'Help'` | `math.typeOf(math.help('sqrt'))`
math.Help | `'Help'` | `math.typeOf(math.help('sqrt'))`
math.Index | `'Index'` | `math.typeOf(math.index(1, 3))`
math.Matrix | `'Matrix'` | `math.typeOf(math.matrix([[1,2], [3, 4]]))`
math.Range | `'Range'` | `math.typeOf(math.range(0, 10))`
math.ResultSet | `'ResultSet'` | `math.typeOf(math.evaluate('a=2\nb=3'))`
math.Unit | `'Unit'` | `math.typeOf(math.unit('45 deg'))`
math.AccessorNode | `'AccessorNode'` | `math.typeOf(math.parse('A[2]'))`
math.ArrayNode | `'ArrayNode'` | `math.typeOf(math.parse('[1,2,3]'))`
math.AssignmentNode | `'AssignmentNode'` | `math.typeOf(math.parse('x=2'))`
math.BlockNode | `'BlockNode'` | `math.typeOf(math.parse('a=2; b=3'))`
math.ConditionalNode | `'ConditionalNode'` | `math.typeOf(math.parse('x<0 ? -x : x'))`
math.ConstantNode | `'ConstantNode'` | `math.typeOf(math.parse('2.3'))`
math.FunctionAssignmentNode | `'FunctionAssignmentNode'` | `math.typeOf(math.parse('f(x)=x^2'))`
math.FunctionNode | `'FunctionNode'` | `math.typeOf(math.parse('sqrt(4)'))`
math.IndexNode | `'IndexNode'` | `math.typeOf(math.parse('A[2]').index)`
math.ObjectNode | `'ObjectNode'` | `math.typeOf(math.parse('{a:2}'))`
math.ParenthesisNode | `'ParenthesisNode'` | `math.typeOf(math.parse('(2+3)'))`
math.RangeNode | `'RangeNode'` | `math.typeOf(math.parse('1:10'))`
math.SymbolNode | `'SymbolNode'` | `math.typeOf(math.parse('x'))`
## Syntax
```js
math.typeOf(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | * | The variable for which to test the type.
### Returns
Type | Description
---- | -----------
string | Returns the name of the type. Primitive types are lower case, non-primitive types are upper-camel-case. For example 'number', 'string', 'Array', 'Date'.
## Examples
```js
math.typeOf(3.5) // returns 'number'
math.typeOf(math.complex('2-4i')) // returns 'Complex'
math.typeOf(math.unit('45 deg')) // returns 'Unit'
math.typeOf('hello world') // returns 'string'
```