I have used the ternary operator in php $foo = get_field('foo') ?: null; but I'm looking forn an equivalent in javascript. So far I've tried the var foo = <?php echo $foo; ?> || null;. But since <?php echo $foo; ?> in this case is null/empty the console is giving me the error Uncaught SyntaxError: Unexpected token || since the variable is var foo = || null;.
Is there another way of using ternary operators in javascript?
var foo = ('<?php echo $foo; ?>') ? '<?php echo $foo; ?>' : null;didn't work?$fooisnull.<?php ... ?>