typeof(null) = "object"
You are doing if typeof(null) == "null" and therefore the code fails. You should directly compare a null and not use a type comparison. The null value has not been 'caught' and then it tries to read the length of this value, which produces this error.
if typeof(null) == "null"
You have to check first for null and then access the array. ;-)
"var highest = array;" is the first access....