Tuesday 11 April 2017

New ECMA Script 6 ES6 Ternary operators

I struggled to wrap my head around these two new operators, the && and the ||.

So I decided to write a post about them to explain them to myself.

var || 'hi'         will return  'hi' when false
var && 'hi'     will return 'hi' when true


So:
var || 'hi' means:

return 'hi' if var is false
    --or--
var ? var : 'hi'

and:
var && 'hi' means:

return 'hi' when var is true
    --or--
var ? 'hi' : var

Devlog 8: AI and Radar explanation.