I am trying to update a lib I got from GitHub and there is a strange condition I have never seen before, can someone help me understand what is this?
As I understand _c = _b === null means that _c get's a value of true or false... and later on _c !== undefined will always be true.. am I missing something?
const _b = { isWrappable: true, insertedTag: false };
let _c;
const status = (_c = _b === null || _b === undefined ? undefined : _b.isWrappable) !== null && _c !== undefined ? _c : false;
console.log(status);
after this line status is true
Now, how can I change this line to avoid Unexpected assignment within ConditionalExpression. because everything I tried gives me false, for example:
const _b = { isWrappable: true, insertedTag: false };
const _c = _b === null;
const test = (_c || _b === undefined ? undefined : _b.isWrappable) !== null && _c !== undefined ? _c : false;
console.log(test);
Thanks
I've solved it :) in my research I found Nullish coalescing operator (??) and solved my problem So the answer is
const _b = {
isWrappable: true,
insertedTag: false
};
const status = _b?.isWrappable ?? false;
console.log(status);
The optional chaining operator and Nullish coalescing operator solved that mess.