-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
On most templating/string formatting implementations, falsy values result in an empty string:
"#{something} here"
=> " here"
whereas in CoffeeScript you get the .toString() representation:
something = x if y // condition fails
"#{something} here"
=> "undefined here"
something = null
"#{something}"
=> "null"
You can say this matches expectations, coming from js, but it could be better. I have yet to see a case where you actually want to print "undefined", "false" or "null" to a string, so returning an empty string would break expectations in a good way :) If you really want it .toString() and typeof will still be there for you.
As a result, this:
console.log "#{not(i%3) and 'fizz' or ''}#{not(i%5) and 'buzz' or ''}" or i for i in [1..100]
could be written as
console.log "#{'fizz' if !(i%3)}#{'buzz' if !(i%5)}" or i for i in [1..100]
That would at principle mean wrapping interpolated expressions in (expression || ''). That wouldn't work for 0 though. Special delimiters?