JavaScript Syntax Part II: Lodash project .findkey() method

Please I need help to understand why my code wouldn’t work with my predicate function defined and
why the code works without an explicit predicate function definition.

findKey: function(object,predicate){
//code does not pass codecademy test when I activate the predicate function definition
below by removing the comment below.
//predicate = val => {(val !== undefined)? true:false};
for (const prop in object){
let value = object[prop];
let predicateReturnValue = predicate(value);
if (predicateReturnValue) {
return prop;
}
}
return undefined;
}

link: https://gist.github.com/ef0b1964915d530cb511774c33bc6efe

You aren’t supposed to supply the predicate function. The test supplies its own predicate function as an argument to your method so that it can make sure that your method is working. That’s why it’s one of the parameters of the method.

If you’re trying to test the method yourself, you can pass it a predicate function outside of the method too.

Side note: Though it won’t impact the outcome of the test because you aren’t supposed to create your own, the predicate function you did create is invalid. Since you used the curly braces {} with your arrow function, you don’t get implicit returns. This makes it so your predicate will always return undefined

Many thanks @selectall for your quick and helpful reply. It is clear to me now how predicate works in this context and I do appreciate.

On the side note, I believe understand better now (hopefully).
If my understanding is good now. The valid short hand will be:

const predicate = val => (val !== undefined)? true:false;
or
const predicate = val => ((val !== undefined)? true:false);

If I desire to use curly braces it should be:
const predicate = val => {
if (val !== undefined) {
return true;
} else {
return false;
}
}

Yes, those would be valid predicate functions.

You could even just add the return keyword to the one you previously wrote to make it valid too:

const predicate = val => {return (val !== undefined)? true:false}

Thank you. Appreciated.