Question about .has()

I am doing this looking at the has() method

Here’s my code:

  has: function (object, key){
                let value = object[key];
                // if (value === ''){return false}
                if (value !== null){
                        return true;
                } else if (value === ''){return false;}
        } //end of has() function

here’s the terminal output

_.has() Tests:
1 - _.has() is defined - Passed!
2 - Returns true if an object has a value at a specified key - Passed!
3 - Returns false if an object does not have a value at a specified key - Failed: _.has({"key": "value"}, "notKey") returned true instead of false.

my question is about the meaning of object does not have a value at a specified key → does it mean that the object has a key and the key has no value in it - key:
or does it mean the object simply does not have the key in it ??
Thank you

The last test case is saying that, even if the key passed into the has function corresponds to no value. For example, if you passed in the following arguments:

has({"1":2, "2":3, "3":4}, "5")

There is no "5" key in the object I passed into has. That means there will be no value at the key "5", not just an empty string, which is still a value.


As an additional note, this (trying to access the value from a key that does not exist in the object) logs undefined:

console.log({"1":null, "2":3, "3":4}["5"]);

I hope this helps!

Am I correct in thinking that both empty string and undefined are both falsy values??

Indeed you are!