Please help me understand this basic JS concept involving objects and properties

Since myObj is not a part of the checkObj function, how can checkProp contain myObj’s properties/values when you call myObj[checkProp]? I’m new to learning JS and this is going a bit over my head.

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

function checkObj(checkProp) {
  if(myObj.hasOwnProperty(checkProp)) { 
    return myObj[checkProp]; 
  } else {
    return "Not Found";

MyObj is part of the window scope (in Node its called global scope) in your example, as is the function checkObj. Since they both are a member of the same scope or “closure” the function checkObj can read var myObj.