So this is a recurring problem that I have and have not found another example for SO, like this:
When rendering Jade templates, I get 'variableName' undefined even when using -if(variableName) in the template.
Example (I use this as partial for flash info messages):
-if(info) - if(info.length){ ul -info.forEach(function(info){ li= info -}) -}
This returns “information” rather than “nothing” if there is no flash information. Does anyone know what I'm doing wrong?
I know the typeof(variable) != 'undefined option, as mentioned. If I wanted to do something like -if (typeof(req.session.user) != 'undefined') , I would have to do 3 nested `if (typeof (req)! = 'Undefined'. This is my only option ?
source share