I had an if statement in code which checks whether an object is defined and then check for equality for one of its properties. My if statement was like:
if(obj && obj.a !== x) { // do something }
But now I used optional chaining and changed my if statement to:
if(obj?.a !== x) { // do something }
But now my code is not working correctly in this case. The code enters if statement even when obj is undefined. Please could somebody explain why is this happening?