True/ False Operator

What is the difference btw this:

function checkObj(obj, checkProp) {
  if (obj.hasOwnProperty(checkProp)) { //look here
    return obj[checkProp];
  } else {
    return "Not Found";
  }
}

And this:

function checkObj(obj, checkProp) {
  if (obj.hasOwnProperty(checkProp)==True) { //look here
    return obj[checkProp];
  } else {
    return "Not Found";
  }
}

Those do basically the same thing. The statement at the head of an if is always weakly compared to true, so manually weakly comparing to true with == true is redundant.

True (with a capital ‘T’) isn’t a keyword.
But there is no difference at all between
obj.hasOwnProperty(checkProp) === true
and
obj.hasOwnProperty(checkProp)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.