If I have a parameter of type Object or null, should I document it as {Object} or {?Object} or {Object|null}?
I read https://jsdoc.app/tags-type.html and it says {?number} means either a number or null, but I'm not sure if I need this for objects, or just primitives.
In javascript, you can use the optional chaining
like element?.addEventListener()
to check for null or not. So because of this, it's more intuitive for {?Object}. Just make sure that it is actually accepting null
and not undefined
. They have separate meanings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With