I was always using the ||
as a nullish coalescing sort of operator. Either A
or B
.
But if I do something like,
1 const a = null
2 const b = '123'
3
4 console.log(a || b) // 123
5 console.log(a) || console.log(b) // null, 123
Why are BOTH console logs executed on line 5? Even if a === null
, shouldn't it just execute the first console log, and not look at console.log(b)
?