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
51 lines (33 loc) • 1.17 kB
Markdown
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
Evaluate an expression.
Note the evaluating arbitrary expressions may involve security risks,
see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
```js
math.evaluate(expr)
math.evaluate(expr, scope)
math.evaluate([expr1, expr2, expr3, ...])
math.evaluate([expr1, expr2, expr3, ...], scope)
```
Parameter | Type | Description
--------- | ---- | -----------
`expr` | string &
`scope` | Object | Scope to read/write variables
Type | Description
---- | -----------
* | The result of the expression
```js
math.evaluate('(2+3)/4') // 1.25
math.evaluate('sqrt(3^2 + 4^2)') // 5
math.evaluate('sqrt(-4)') // 2i
math.evaluate(['a=3', 'b=4', 'a*b']) // [3, 4, 12]
let scope = {a:3, b:4}
math.evaluate('a * b', scope) // 12
```
[ ](parse.md),
[ ](compile.md)