TypeScript 3.7 RC & Nullish Coalescing
null, undefined default value
https://devblogs.microsoft.com/typescript/announcing-typescript-3-7-rc/#nullish-coalescing
let x = foo ?? bar();
// Again, the above code is equivalent to the following.
let x = (foo !== null && foo !== undefined) ?
foo :
bar();
// The ?? operator can replace uses of || when trying to use a default value.
function initializeAudio() {
let volume = localStorage.volume || 0.5
// ...
}
refs
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!