1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- ###
- Operators
- ---------
- CoffeScript JavaScript
- == is ===
- != isnt !==
- not !
- and &&
- or ||
- true yes on true
- false no off false
- ###
- paid = coffee = pour = ->
- if paid() and coffee() is on then pour()
- addCaffeine = Decaf = ->
- addCaffeine() if not Decaf()
- addCaffeine() unless Decaf()
- # Combined range checks
- level = 4
- if 2 < level < 5
- alert "In range"
- # Functional switch.
- message = switch cupsOfCoffee
- when 0 then 'Asleep'
- when 1 then 'Eyes open'
- when 2 then 'Buzzed'
- else 'Dangerous'
- # Existential check: not undefined and not null.
- if cupsOfCoffee?
- alert('Exists')
- alert 'Exists' if cupsOfCoffee?
- # Not strictly identical to the two shorter forms below.
- if not cupsOfCoffee?
- cupsOfCoffee = 0
- cupsOfCoffee = 0 unless cupsOfCoffee?
- cupsOfCoffee ?= 0
- coffeePot?.brew()
- # Like Ruby "try"
- vehicle.start_engine?().shift_gear?().crank?().press_gas?()
|