Dress to Impress


This should print out "shorts" but still getting false?

var suitcase = {
shirt: "Hawaiian",
shorts: "red",

if (suitcase.hasOwnProperty ("suitcase.shorts")) {

console.log ("shorts");


console.log ("false");


Hi! I guess you should just put 'shorts' within parenthesis instead of 'suitcase.shorts'!


is dot notation not reliable?


Dot notation is Just wrong in this case because when you call hasOwnProperty you call It on an object (in this case suitcase). You are checking if suitcase has a property called 'shorts'! So within hasOwnProperty parenthesis you write the name of the property you are look in for.If you write
suitcase.hasOwnProperty( ' suitcase.shorts') It's gonna check if the object ha a property named suitcase.shorts, not just shorts. This is just the correct syntax of hasOwnProperty.


"hasOwnProperty" returns "true" if condition is right. Since you added ==> shorts:"red" in var suitcase { }, it should print "red" because this condition will be true. You just need a little modification.

//to print "blue", just remove shorts:"red" from var suitcase
suitcase.shorts = "blue"; // assign any value you want.