Ever encountered an error of the sort? Cannot read property 'colour' of undefined In this case, you probably expected an object, yourObjectName to have a colour property. So you went ahead to make use of it this way: if (yourObjectName.colour === 'bl...

Markdown supported ยท โโต to post
Ugochukwu Ejiogu
Welcome to Hashnode, I've been using optional chaining at my work place without knowing what's it called ๐ฒ, I should have asked questions...
Nicely written and explained!
This would still throw cannot read property color of undefined if yourObjectName does not exist:
if (yourObjectName.color && yourObjectName.color === 'blue') {
return 'Blue is cool';
}
Perhaps you meant:
if (yourObjectName && yourObjectName.color === 'blue') {
return 'Blue is cool';
}
Sanjeev Vishwakarma
#Javascript #angular #css #bootstrap #nodejs
Thanks for sharing found it very useful .