That's a good list, just one thing I would like to mention in tips 4 and 5. It's better to check if the value is null or undefined using Nullish Coalescing Operator (??) since for some cases it might be an unexpected behavior:
null
undefined
Nullish Coalescing Operator (??)
const foo = null || 42; console.log(foo); // expected output: 42
const foo = 0 || 42; console.log(foo); // expected output: 0, but will be 42
So, in that case ?? will work as expected
??
const baz = 0 ?? 42; console.log(baz); // expected output: 0 and will be 0
Thank you for your work!
In some cases Nullish Coalescing Operator is the best choice. Thanks for the assistance.
Nullish Coalescing Operator
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.
That's a good list, just one thing I would like to mention in tips 4 and 5. It's better to check if the value is
nullorundefinedusingNullish Coalescing Operator (??)since for some cases it might be an unexpected behavior:So, in that case
??will work as expectedThank you for your work!
In some cases
Nullish Coalescing Operatoris the best choice. Thanks for the assistance.