Access an object with dot property


I tried to use dot property but the code only worked with brackets. I can’t understand why?

Should we use brackets when there is space in the property.

Here is what I tried to do and didn’t work.

var myObj = {
gift: “pony”,
pet: “kitten”,
bed: “sleigh”

function checkObj(checkProp) {
// Your Code Here
return myObj.checkProp; /* over here i used dot property. The code worked when I changed it to brackets. return myObj[checkProp];*/
return “Not Found”;

// Test your code by modifying these values

1 Like

Thanks for the help!