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 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/11749345.html
未经授权禁止转载,违者必究!