What is the proper way to check for existence of variable in an EJS template (using ExpressJS)?

The same way you would do it with anything in js, typeof foo == 'undefined', or since “locals” is the name of the object containing them, you can do if (locals.foo). It’s just raw js :p

Leave a Comment