I'm seeing lots of code using the pattern:
if (typeof a.b === 'undefined') { ...
Now I'm translating this to:
(if (nil? (-.b a)) ...
Is that appropriate - or am I losing some crucial data?
My question is: What is the ClojureScript analogue of typeof ... undefined
from JavaScript?
A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned .
The typeof undefined is the string "undefined" — and undefined is a falsy value that is loosely equal to null but not to other falsy values.
variable === undefined VS typeof variable === “undefined” Here the assigned variables don't have any value but the variable exists. Here the type of variable is undefined.
For checking for possibly undefined
references you can use cljs.core/exists?
:
(when-not (exists? js/unknownReference)
...)
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