TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why ++[[]][+[]]+[+[]] = 10 in JavaScript

159 点作者 smharris65超过 13 年前

14 条评论

wonnage超过 13 年前
Seems like "this is why Javascript sucks!" is a common reaction here, which I find strange on a "hacker" community. It's a fun little brainteaser, not production code. Use your head a little?
评论 #3403805 未加载
thought_alarm超过 13 年前
My question is, <i>when</i> did that start working in Javascript?<p>Does this trick work in Brendan Eich's first JS implementaion in Netscape 2.0? Which came first, the spec or the implementation?
评论 #3406998 未加载
评论 #3402564 未加载
gmcabrita超过 13 年前
((__=!($=[]))+$)[$++]+(_={}+$)[$]+_[$++]+_[$]+(__+_)[--$]+(!__+_)[$]<p>returns "foobar"
评论 #3401733 未加载
billpg超过 13 年前
This sort of thing really bothers me with Javascript. Using the unary + operator on an array should be an error. Hiding errors by having implicit type convertions doesn't help me fix those errors.<p>You may say that users don't need to see to see strange error messages they don't understand. Quite right, what we need instead is to have a way for browsers to transmit uncaught exceptions in JS to the server.
评论 #3404438 未加载
评论 #3402188 未加载
raganwald超过 13 年前
From wtfjs.com:<p><pre><code> ",,," == Array((null,'cool',false,NaN,4)); // true</code></pre>
评论 #3401574 未加载
zackzackzack超过 13 年前
Thought some and came up with an way to convert whichever natural number you want into this form.<p><a href="https://gist.github.com/1531201" rel="nofollow">https://gist.github.com/1531201</a><p>It depends on underscore.js for the functional bits.
评论 #3403921 未加载
SanjayUttam超过 13 年前
Reminds me of: <a href="http://adamcecc.blogspot.com/2011/01/javascript.html" rel="nofollow">http://adamcecc.blogspot.com/2011/01/javascript.html</a>
gosub超过 13 年前
I can't find a link to a page, from some time ago, in which every letter and number was obtained combining only parentheses and punctuation.
评论 #3403161 未加载
tingletech超过 13 年前
related: <a href="http://news.ycombinator.com/item?id=1154338" rel="nofollow">http://news.ycombinator.com/item?id=1154338</a>
ajankovic超过 13 年前
I wonder how people come up with this kind of code to begin with?
评论 #3401465 未加载
recoiledsnake超过 13 年前
This is the reason I prefer strongly typed languages. Allowing developers to play fast and loose with data types only leads to less maintainability down the road and makes code difficult to read.
评论 #3401421 未加载
评论 #3401665 未加载
评论 #3401917 未加载
评论 #3401455 未加载
评论 #3402089 未加载
评论 #3402014 未加载
评论 #3401565 未加载
评论 #3402150 未加载
评论 #3401413 未加载
ultimatewarrior超过 13 年前
Reminds me of the J programming language
评论 #3402478 未加载
评论 #3401630 未加载
billpg超过 13 年前
If you rely on that sort of thing in production code, you're doing it wrong.
评论 #3420524 未加载
kickingvegas超过 13 年前
Putting this in the category of "not going to think hard about this, because it's only going to make me upset and angry."