site
site copied to clipboard
📝 Article: the difference between optional chaining and non-null assertions
Overview
?. and !. aren't the same. I should write an article explaining the difference.
One common slipup I've seen is people doing this:
const myValue = document.getElementById(someId)?.textContent;
...and wondering why myValue is string | undefined, not string.