# Calculate Standard Deviation in JavaScript

Standard deviation is a measure of how far a set of numbers deviates from the average. Small standard deviation means the numbers are all relatively close to the mean. JavaScript doesn't have a built-in standard deviation function, but Math.js is a well supported library with a full featured standard deviation function.

Here's an example of using Math.js' `std()`

function to calculate standard deviation.

```
const math = require('mathjs');
// Can pass an array to the `stddev()` function:
math.std([5, 5, 5, 5]); // 0
// Or a list of arguments (also called a "spread")
math.std(1, 5, 9); // 4
```

Math.js also has support for bias correction. Math.js' `std()`

function uses Bessel's correction by default, but takes a 2nd argument `normalization`

for configuring this. By default, given an array of length `n`

, the `std()`

function divides the variance by `n - 1`

. You can pass `'uncorrected'`

to make `std()`

divide by `n`

, or `'biased'`

to make `std()`

divide by `n + 1`

.

```
const math = require('mathjs');
// Must pass an array if you're using options
math.std([1, 3], 'uncorrected'); // 1
math.std([2, 4, 6, 8], 'biased'); // 2
```

## More Fundamentals Tutorials

- How to Clear an Array in JavaScript
- How to Check if a Variable is an Integer in JavaScript
- How to Check Whether a String Does Not Start With a Regex in JavaScript
- Check Whether a String Starts with a Regexp in JavaScript
- Format a JavaScript Date to YYYY MM DD
- Array toString() in JavaScript
- How to Parse URL in JavaScript into Host, Path, Search, and Hash