Note that var and let keywords let you make undefined but const does not
let x // syntax error const y
For bonus points, add a fallback for undefined or null or falsy (zero, empty string)
let x const y = x || "default" console.log(y.toUpperCase())
Or in newer versions of JS, you can use this to handle null and undefined, but it won't replace zero or empty string.
let y const x = y ?? "default"
michaelcurrin.github.io/dev-cheats...
TypeScript can enforce missing values for you so you don't have to throw errors or use a fallback.
I didn't even consider const. Thank you for pointing that out!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Note that var and let keywords let you make undefined but const does not
For bonus points, add a fallback for undefined or null or falsy (zero, empty string)
Or in newer versions of JS, you can use this to handle null and undefined, but it won't replace zero or empty string.
michaelcurrin.github.io/dev-cheats...
TypeScript can enforce missing values for you so you don't have to throw errors or use a fallback.
I didn't even consider const. Thank you for pointing that out!