Passing a function as a argument. Why does it work?

You can check out the challenge to better understand what I’m talking about.

When I write this code into VSCode and use the browser console to see the results, it tells me that “func is not a function”.

So, why does this work in the FCC challenge, but not in the browser?

function findElement(arr, func) {
let num = 0;
for (let i = 0; i < arr.length; i++) {
  num = arr[i];
  if (func(num)) {
    return num;
return undefined;

console.log(findElement([1, 2, 3, 4], num => num % 2 === 0));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Finders Keepers

Link to the challenge:

Hello @anghelpaul99.

I ran the same code in the browser console but I don’t get the error you are referring to.

That’s weird. Thanks for letting me know.

Check whether your browser needs to be updated.

It was because I was using strict mode JS in VSCode