I know this was only given as an example, but there's a small mistake:
Screenshot:
What is wrong?
It says that let volume = localStorage.volume || 0.5 will be 0.5 when localStorage.volume is set to 0, but everything stored in localStorage can only be a string and "0" is truthy.
localStorage.volume = 0; // saved as "0"
let volume = localStorage.volume || 0.5; // volume = "0" || 0.5
volume === "0" // Not 0.5 as mentioned in the example
https://github.com/microsoft/TypeScript-Handbook/blob/master/pages/release%20notes/TypeScript%203.7.md#nullish-coalescing
I know this was only given as an example, but there's a small mistake:
Screenshot:
What is wrong?
It says that
let volume = localStorage.volume || 0.5
will be0.5
whenlocalStorage.volume
is set to0
, but everything stored in localStorage can only be astring
and"0"
is truthy.