使用??时,只有当值 1 为 null 或 undefined 时才返回值 2;
使用||时,值 1 会转换为布尔值判断,为 true 返回值 1,false 返回值 2

// ??
undefined ?? 2; // 2
null ?? 2;      // 2
0 ?? 2;         // 0
"" ?? 2;        // ""
true ?? 2;      // true
false ?? 2;     // false

// ||
undefined || 2; // 2
null || 2;      // 2
0 || 2;         // 2
"" || 2;        // 2
true || 2;      // true
false || 2;     // 2
Last modification:March 13, 2022
If you think my article is useful to you, please feel free to appreciate