-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ternary operator? #46
Comments
I use the ternary operator a lot too, and CoffeeScript uses it whenever possible (because it's already an expression). There's no special syntax for it in CoffeeScript, just this:
Compiles into:
I realize its slightly longer, but less cryptic, I hope. If you want to break it up, this will compile in to the exact same JavaScript ternary:
As to the triple equals, there is not going to ever be a |
Thanks Jeremy, that works fine, i didn't know about that syntax. however if you ever decide to allow a straight ternary syntax, you'll have my vote :-) |
It's a real gotcha in my opinion because a C/Java/JS style ternary doesn't cause the compiler to complain, but gives unexpected results.
|
alert(5 > 4 ? "bigger" : "not bigger") # alerts "bigger" |
@mcanes Where are you trying this? Both my local CoffeeScript install, and the 'Try CoffeeScript' page, alert 'true' with that code. Both with and without your parentheses. |
@ukslim: this issue is more than a year and a half old and long settled. If you have a question, please open a new issue, ask it on IRC, or ask it in the google group. |
@ukslim On the 'Try CoffeeScript' page using chrome and Firefox This is the coffee script code alert( if 5 > 4 then "bigger" else "not bigger") and the generated js alert(5 > 4 ? "bigger" : "not bigger"); |
Are there plans to allow the use of the ternary operator in coffee-script?
I'm converting some code that uses it a lot.
Also, will "===" be allowed in the future? right now i convert them to "==" which coffee script converts back to "===".
The text was updated successfully, but these errors were encountered: