Question: ```
// Should equal 0 when an empty Array is entered

function getLengthOfShortestElement(arr) {

  var shortestElement = Infinity;

  for(var i=0; i < arr.length; i++) {
    if(arr[i].length < shortestElement) {
      shortestElement = arr[i].length;
    } else if (arr[i].length === 0) {
      return 0;
    } 
  }
  return shortestElement;
}

var output = getLengthOfShortestElement([]);
console.log(output);

```

Judging by the code why isn't it outputting 0? Instead it outputs Infinity..

Answer: 
If the array is empty, `shortestElement` is still `Infinity`, since the loop never runs and you don't reassign it.

You can simply check for an empty array at the beginning.

Another improvement is to initialize `shortestElement` from the first element, and then loop starting from the second element.

You should also check for a zero-length element before checking if the length is less than `shortestElement`, since `0` will always be less and you won't ever get to the `else if` (unless there are two zero-length elements in the array).

```js
function getLengthOfShortestElement(arr) {
  if (arr.length == 0) {
    return 0;
  }

  var shortestElement = arr[0].length;

  for (var i = 1; i < arr.length; i++) {
    if (arr[i].length === 0) {
      return 0;
    } else if (arr[i].length < shortestElement) {
      shortestElement = arr[i].length;
    }
  }
  return shortestElement;
}

var output = getLengthOfShortestElement([]);
console.log(output);
```
Since `arr.length == 0` when you pass an empty array, the `for` loop's condition will be false at the very start, and so the variable `shortestElement` will remain what it was initiliased to: `Infinity`.

However, if you would call the function with `[[]]` instead of `[]`, *then* you *do* have an empty array in your array, and you *will* get 0.

This shows there is a difference between an empty array and an array that has an empty array. Your function is designed to look at the arrays *inside* the array you pass. If there are none, it cannot say what is the *shortest* among those... that is truly undefined, so `Infinity` is not such a bad answer in that case.

Compare to what `Math.min` returns when you pass it no arguments at all:

```js
console.log(Math.min(3, 1)); // 1
console.log(Math.min(3)); // 3
console.log(Math.min()); // Infinity
```