Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the ClojureScript analogue of typeof ... undefined from JavaScript?

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?

like image 252
hawkeye Avatar asked Apr 25 '16 07:04

hawkeye


People also ask

What is typeof undefined in 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 .

What is the value of typeof undefined typeof null?

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.

Why typeof undefined is undefined?

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.


1 Answers

For checking for possibly undefined references you can use cljs.core/exists?:

(when-not (exists? js/unknownReference)
  ...)
like image 146
Piotrek Bzdyl Avatar answered Nov 05 '22 14:11

Piotrek Bzdyl