New to JavaScript and can't figure out what I'm doing wrong. I'm attempting to get the function to either return the last element of the array if there is such an argument (I got this part to work). And if there is no argument to return null. However, when I try to get it to return an empty array, it only returns as undefined and not null. If you could explain to me what I'm doing wrong without just showing me the answer I would be appreciative.
This is the code I have written:
function lastElement(array) {
if (array !== "") {
return array[array.length - 1];
} else {
return null;
}
}