# ui/autolayout/layoutterm (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/ui/autolayout/layoutterm/

A term of an expression. coefficient * variable.

## LayoutTerm

A term of an expression. coefficient * variable.
- A component of LayoutExpression.
- Immutable object. Arithmetic operations always return a new instance.

Example: Build a center expression with a term of coefficient 0.5

```js
import { LayoutSolver, LayoutVariable, LayoutTerm, LayoutExpression } from "./build/vanilla.js";

const width = new LayoutVariable("width");
const halfWidth = new LayoutTerm(width, 0.5);
const centerExpression = new LayoutExpression([halfWidth], 10);
const solver = new LayoutSolver();
const widthExpression = LayoutExpression.fromVariable(width);
const widthConstraint = widthExpression.equalTo(300);
solver.addConstraint(widthConstraint);
solver.updateVariables();
const termValue = halfWidth.getValue();
const centerValue = centerExpression.getValue();
console.log(termValue, centerValue);
```

- `constructor(variable, coefficient)` (constructor, since 0.2.1): Constructor.
  - `variable` LayoutVariable: Variable of the term. (undefined or null is kept as null and the value is 0, the solver skips such terms)
  - `coefficient` number: Coefficient. (1 if not a number)
- `getVariable()` (method, since 0.2.1): Returns the variable.
  - returns LayoutVariable | null: Variable of the term. (null if none)
- `getCoefficient()` (method, since 0.2.1): Returns the coefficient.
  - returns number: Coefficient.
- `getValue()` (method, since 0.2.1): Returns the evaluated value (coefficient * variable.value). 0 if there is no variable.
  - returns number: coefficient * variable value. (0 if there is no variable)
