Here’s another variant of the above that I’ve found helpful that uses the ternary operator:
(execution.hasVariable("myVar") ? execution.getVariable("myVar") : "null")
This tests for the existence of the variable first and if found can use its value, otherwise it is set to null.
Another use would be short-circuiting in a conditional statement like this:
if ((execution.hasVariable("myVar")) && (execution.getVariable("myVar")) == "whatever")) { ....