undefined - How do you implement a guard clause in JavaScript? -


I want to protect my actions against null-ish values ​​and only if "defined" is the value then continue .

After the solution suggested to be equal to two times undefined: if (some == undefined) . The problem with this solution is that you can declare an undefined variable.

Then my current solution is to check for the blank (if some == empty) which checks for the uncertainly uncertain and if I want to capture AdiNulti Francy Values So I check if (some) .

Check the test here:

Now am I missing something here?

Matthias

and anything ( if (! _someUndefinedVarName) ) will fail.

Basic example:

Remove the first block and you will get:

_someUndefinedVarName is not defined

Comments