Ternary

In JavaScript you can use a ternary statment in place of an 'If/Else'.

console.log(7 % 2 === 0 ? '7 is odd' : '7 is even')

const isBlue = true;
console.log(isBlue ? 'Ive never seen a blue duck before.' : 'Standard duck')
$node jsbyexample.js
7 is odd
I've never seen a blue duck before.
Back to main