While practicing JavaScript, I came across a sample code where I tried to call a function from an array. However, the output returned undefined along with the expected result from the function. I'm confused as to why this is happening, especially since I've correctly called the index of the array containing the function. Can someone help me understand what's going on?
const arr = [
"test1",
"test2",
function(){console.log("hi")}
];
console.log(arr[2]());
Output:
Babel Compiler v6.4.4
Copyright (c) 2014-2015 Sebastian McKenzie
hi
undefined
=> undefined