How to check express local variable exists when in script tag of jade?

Problem

I have a data variable sent to client-side, but it may not always be included as a variable in the express locals. If it doesn't exist, var data = !{JSON.stringify(data)}; returns var data = ; which causes a js error.

I've tried using conditionals prefixed with '-' but that doesn't seem to work.

script(type='text/javascript')
    - if locals.data
        var data = !{JSON.stringify(data)};
    - else
        var data = {};

How do I give it a default if locals.data is undefined?

Problem courtesy of: dule

Solution

Don't you hate it when you wrack your brain, then ask for help on SO, only to figure it out 5min later...

Looks like the following keeps the jade and javascript happy:

var data = !{ JSON.stringify(locals.data || '') };
Solution courtesy of: dule

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.