CoffeeScript introduces some very nice logic and conditional features, some also borrowed from other scripting languages. The
unless keyword is the inverse of the
unless can take the postfix form, meaning statements can go at the end of the line.
CoffeeScript also provides plain English aliases for some of the logical operators. They are as follows:
truecan also be
Putting all this together, let's look at some code to demonstrate it:
car.switchOff() if car.ignition is on service(car) unless car.lastService() > 15000 wash(car) if car.isDirty() chargeFee(car.owner) if car.make isnt "Toyota"