function test(val) {
const hasError = val ?? true;
if (hasError) {
//error handling...
} else {
//do something...
}
}
test(null) //error handling...
test(undefined) //error handling...
test('text') //error handling...
test(true) //error handling...
like this case i want to filter 'null' and 'undefined'
but it`s work every truthy value.
So i have only one option...
const hasError = (val === undefined || val === null);
Is there any way of use nullish operator in this case?
and when nullish operator is used generally?
thank you