## DEV Community # Space Complexity in Algorithm

When we talk about space complexity, remember that we are talking about the space that an algorithm takes up as the size of the input increases. We are indicating auxillary space complexity here means we are just focusing on what happens inside the algorithm.

Things to remember in Space Complexity -

1. Primitive things like booleans numbers, undefined, null and JavaScript are constant space.
2. Strings require `o(n)` space where n is the length of the string. For example a string with 10 characters take more space than a single character string.

Let's see an example -
Determine the space complexity of the following -

``````Determine the space complexity for the following function

function sum(arr) {
let total = 0;
for (let i = 1; i < arr.length; i++) {
total+= arr[i];
}
So this function called sum, it takes an array and it just sums all the items in the array. We have a variable `total` that starts at 0. Then we have the loop that goes from 0 to the end of the array and we're just adding in the value