Re-creating the Lodash Library - Implement _.has() - Need help


Many thanks for your answer mtf. It did help :slight_smile:

On .has() I’d have a question too. I have the following code:

has(object, key) {
return object.key != undefined ? true : false

and it does not pas the test although it’s not dissimilar to your code further above. The terminal says that ‘has was not proper defined’. Is this because I did not include any keys in the object for the method to run on?

Thanks a lot


Don’t think so… It may have to do with the dot notation. Did you try using a subscript?



yeah, I did. same result. I don’t think the code is correct though, I’m firing it at a console with a test object to see what it does and keep getting stupid error messages of unexpected tokens and the rest of it. frustrating.


Errors can appear elsewhere that trip things up. Please post your entire _ object so we can inspect it.

Something else to consider.

return object[key] != undefined ? true : false

This is not a case where a ternary is of any importance. The expression is already boolean.

return object[key] !== undefined;

will return true or false. Note the operator is strict. Avoid using loose comparisons, == or != as this can lead to potential problems down the road.


Hi mtf,

follow-up on this. This code worked:

has(object, key) {
return object[key] !== undefined

but this one didn’t:

has(object, key) {
return object.key !== undefined

I will steer clear of dot notation from now on when it comes to accessing keys in an object.

Many thanks…


Hi all,
I have this kind of situation could someone figure out what happens here? And why I have this error?


The last line in the editor window seems awry. Should it be something like this,

module.exports = _;