I have the following chaining operator
const age = data.student?.age ? data.student.age: '';
this works fine in my local machine but seems to have problem in another machine. on further investigation i could understand that node js lower version(i suppose version below 12) doesn't support chaining operator. I understand that i can replace this with if condition like below but would like to know suggestions on what is the best possible alternative for this.
function checkAge(data){
if(data && data.student && data.student.age) {
return data.student.age;
} else {
return '';
}
}
const age = checkAge(data);
age
) you want to return a string (''
) when the property does not exist. That seems like a bad choice.Node. js 12 will reach End-of-Life status on 30 April 2022
. Unsupported Node versions is of course a massive security issue.