Ugochukwu Ejiogu
Software Engineer
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 .