In CoffeeScript you can write if-statements with a single line of code. As so often, there are several ways in CoffeeScript to do it. Let me give you some examples:
Source
if hello console.log 'Hello World!' |
Option 1
if hello then console.log 'Hello World!' |
Option 2
console.log 'Hello World!' if hello |
And of course:
console.log('Hello World!') if hello |
if hello then console.log('Hello World!') |
My favourite is the option 2.. the only problem with the one liners is if you want to add more stuff like logging for example you have to break it in two.. and then most likely it will stay two liners 🙂