🖥

#TypeScript で、はてなマーク二個のあいつは、値が null か undefined の場合にだけ、後ろが評価されるみたいだ。

に公開

console.log("A" ?? 'NULL OR UNDEFINED') // A
console.log(1 ?? 'NULL OR UNDEFINED') // 1

console.log(true ?? 'NULL OR UNDEFINED') // true
console.log(false ?? 'NULL OR UNDEFINED') // false

console.log(null ?? 'NULL OR UNDEFINED') // NULL OR UNDEFINED
console.log(undefined ?? 'NULL OR UNDEFINED') // NULL OR UNDEFINED


// js version
//
// var _a, _b, _c, _d, _e;
// console.log((_a = "A", (_a !== null && _a !== void 0 ? _a : 'NULL OR UNDEFINED'))); // A
// console.log((_b = 1, (_b !== null && _b !== void 0 ? _b : 'NULL OR UNDEFINED'))); // 1
// console.log((_c = true, (_c !== null && _c !== void 0 ? _c : 'NULL OR UNDEFINED'))); // true
// console.log((_d = false, (_d !== null && _d !== void 0 ? _d : 'NULL OR UNDEFINED'))); // false
// console.log((_e = null, (_e !== null && _e !== void 0 ? _e : 'NULL OR UNDEFINED'))); // NULL OR UNDEFINED
// console.log((undefined !== null && undefined !== void 0 ? undefined : 'NULL OR UNDEFINED')); // NULL OR UNDEFINED

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/3018

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2020-03-15

Discussion