I have a json object like below
let obj = { 'key1' : 'value1' , 'key2 : { 'key2a' : 'value2a' } }
I wanted to do a ternary operator check which is equivalent to below code
if(obj) {
if(obj.key2) {
if(obj.key2.key2a) {
return obj.key2a;
}
}
}
So, In google chrome console i have tried below to achieve it in simpler way and it worked...
obj?.key2?.key2a? obj.key2.key2a : '0'
If i am trying it in nodejs@12 its giving me syntax error.
Can someone please help me understand this discrepancy ?