Issue
why Null Coalescing is not working with ternary operator. I would expect to get tdy.
const test = {
todo: {
day: 'tdy'
}
}
const filterDayRange = [{
day: 'mon'
}]
const result =
test.todo?.day ?? filterDayRange.length > 0 ? filterDayRange[0].day : 'tdy';
console.log(result)
// expected Output: tdy
Solution
I simply add Parantheses :
test.todo?.day ?? (filterDayRange.length > 0 ? filterDayRange[0].day : 'tdy');
and now it works fine
Answered By - Ali Sattarzadeh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.