TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

WTF does this code do?

10 pointsby benvanabout 11 years ago

6 comments

sigvefabout 11 years ago
This is why you should always use semicolons in JavaScript. Omitting semicolons here turns this:<p><pre><code> var angry = say(&#x27;Garrrr!&#x27;) &#x2F;&#x2F; what should I say? (amIHappy ? happy : angry)() </code></pre> into this:<p><pre><code> var angry = say(&#x27;Garrrr!&#x27;)(amIHappy ? happy : angry)()</code></pre>
zequelabout 11 years ago
Most web browsers (if you&#x27;re running this code in a web browser), will do ASI (automatic semicolon insertion).<p><a href="http://jsfiddle.net/CxUXh/" rel="nofollow">http:&#x2F;&#x2F;jsfiddle.net&#x2F;CxUXh&#x2F;</a> works fine in Chrome, changing the console.log to an alert.<p>Not that I&#x27;m advocating omitting semicolons!
评论 #7460007 未加载
dsschnauabout 11 years ago
Does it return that because `say` isn&#x27;t defined inside its own function definition, so it evaluates as false?
TophWellsabout 11 years ago
It doesn&#x27;t seem to do anything.
rainmakingabout 11 years ago
Hahaha, nice!<p>I&#x27;m getting a linter.
dismal2about 11 years ago
this is idiotic