MS
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' ; }