JavaScript query selectors can return null
querySelector returns null when no element matches, so immediate property access throws. Check the result or enforce the DOM invariant before using it.
- @imsa-mehta▲ 5
"JavaScript query selectors can return null" is a useful thing to know about with javascript / dom. Thanks for sharing it.
Clear note on javascript / dom. "JavaScript query selectors can return null" is the kind of detail that is easy to overlook.
Logical
Gem
- @ohmshawas23▲ 4
Solid
Skillful
- @narwhalix▲ 3
Educational
Specific and to the point: "JavaScript query selectors can return null". Worth a look if you touch javascript / dom.
Perfect
- @deneil2121▲ 3
Valuable
- @ohmshawas23▲ 3
Key
- @mrnarwhal55▲ 2
Smooth
- @deneil2121▲ 2
Fixed
- @dearsohum▲ 1
"JavaScript query selectors can return null" is a useful thing to know about with javascript / dom. Thanks for sharing it.
- @aarya-mehta▲ 1
"JavaScript query selectors can return null" is a useful thing to know about with javascript / dom. Thanks for sharing it.
Brilliant
Stellar
Stellar
Appreciate the write-up on "JavaScript query selectors can return null". Useful for anyone using javascript / dom.
Clear note on javascript / dom. "JavaScript query selectors can return null" is the kind of detail that is easy to overlook.
"JavaScript query selectors can return null" is a useful thing to know about with javascript / dom. Thanks for sharing it.
querySelectorAllnever returns null. It returns an empty NodeList, so check.length.getElementByIdalso returns null when nothing matches. Corrections or other cases welcome below.Timely
Illuminating