I'm currently writing some code that wrappers user-written JavaScript functions, and have come across a point in the logic where I would like to trigger a particular behaviour if the function in question never returns a value i.e. the return
keyword is never evaluated.
Currently I am assuming that if a function returns undefined
, it has not returned, however this is not strictly true—due to the fact a function can always return undefined
, or return the value of an undefined property.
With a function call you can always tell how many parameters were used due to the arguments.length
property, I was wondering if anyone knew of a similar trick for a function's return value?
So, is it possible to tell the difference between the return values of a
, b
or even c
var a = function(){ };
var b = function(){ return undefined; };
var c = function(){ if(1){}else{return undefined;}; };