Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • 19
    logical or is not quite the thing needed in most cases, as you may want it to pick the right operand only if the left is undefined but not when it is defined and falsy. Commented Aug 7, 2014 at 9:06
  • 2
    The CoffeeScript home page uses <script type="text/coffeescript">. Commented Aug 9, 2016 at 22:09
  • 30
    While this answers the question it is almost entirely about coffeescript rather than javascript, and is more than half about describing coffeescript benefits unrelated to the OP. I'd suggest boiling it down to just what's relevant to the question, as wonderful as coffeescript's other benefits are. Commented Oct 4, 2016 at 17:25
  • 4
    Am I going bananas? Surely the objection of user2451227 (currently with 4 votes) is invalid because the ternary's middle operand (i.e. right operand with the Elvis operator) would equally not be picked if the expression/left operand is defined and falsy. In both cases you then have to go x === undefined. Commented Jan 20, 2018 at 17:56
  • 5
    Please consider updating this to mention the optional chaining operator, ?.,. Browser support isn't at the point where I'd use it for general code, but it's heading in that direction. In addition, there's now the nullish coalescing operator (??), with a similar status.
    – Makyen
    Commented Aug 2, 2020 at 16:13