site icon indicating copy to clipboard operation
site copied to clipboard

📝 Article: the difference between optional chaining and non-null assertions

Open JoshuaKGoldberg opened this issue 3 years ago • 0 comments

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.

JoshuaKGoldberg avatar Jul 26 '22 00:07 JoshuaKGoldberg