Function reference · Math

vars

Lists the variables in an expression.

Notation

vars(expression)

Write it in an expression: nerdamer('vars(x+y*z)'), or in the Playground.

Parameters

expression
Any expression.

Returns

A vector of the distinct variables, sorted by name. Constants such as pi are not included.

Examples

Each variable appears once.

vars(x+y*z)
// → [x, y, z]
Open in Playground

Both sides of an equation count.

vars(x=y^2)
// → [x, y]
Open in Playground

The result is sorted by name.

vars(a*x^2+b*x+c)
// → [a, b, c, x]
Open in Playground

pi is a constant, not a variable.

vars(sin(t)+pi)
// → [t]
Open in Playground

A number has no variables.

vars(3)
// → []
Open in Playground

Good to know

  • Use it to find which variables to pass to solve, diff or buildFunction.

JavaScript examples

In JavaScript, .variables() on an expression returns the names as strings.

nerdamer('a*x+pi').variables()
// → ["a","x"]

← Back to Function reference