xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

TypeScript 3.7 RC & Nullish Coalescing

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 发布文章使用:只允许注册用户才可以访问!


posted @ 2019-10-27 22:00  xgqfrms  阅读(119)  评论(3编辑  收藏  举报