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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

JavaScript Coercions Grid

86 点作者 bfoks大约 6 年前

8 条评论

seanwilson大约 6 年前
JavaScript gets a lot of flak about weird coercions but I never found them a big source of errors compared to say more basic things like forgetting function arguments or getting them in the wrong order. Coercions are way less of a problem in TypeScript as well because coercions that change the type will get flagged at compile time.
评论 #19529722 未加载
评论 #19530103 未加载
tuesdayrain大约 6 年前
I'm not entirely sure why all of this even exists, it seems like it creates a lot of potential for bugs. I've been developing in JS for years and I've never intentionally used type coercion. If I ever needed to operate on multiple types I would always explicitly cast them to the correct type beforehand.
评论 #19529716 未加载
评论 #19530584 未加载
wongarsu大约 6 年前
I don&#x27;t really get why `-0 + 0 == 0` is marked as a WTF? I guess getting -0 would be marginally better, but 0 is a perfectly fine answer.<p>I also think `true + 0 == 1` is perfectly reasonable, but I get that this might not be reasonable for everyone. All the other fixes look like genuine improvements.
评论 #19529461 未加载
评论 #19531015 未加载
评论 #19530307 未加载
teddyh大约 6 年前
See also: JavaScript Equality Minesweeper: <a href="https:&#x2F;&#x2F;eqeq.js.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;eqeq.js.org&#x2F;</a>
jacobolus大约 6 年前
Turning +true into 1 and +false into 0 does not seem surprising or problematical. To me this seems like the obviously only correct behavior. Turning these into NaN would be a giant terrible WTF for me.<p>The author might want to add !!foo as an additional type of coercion (to bool).
sarcasmOrTears大约 6 年前
Don&#x27;t worry, it looks scarier than it is
DonHopkins大约 6 年前
Brendan Eich never really understood the concept of equality.<p><a href="https:&#x2F;&#x2F;dorey.github.io&#x2F;JavaScript-Equality-Table&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dorey.github.io&#x2F;JavaScript-Equality-Table&#x2F;</a>
beders大约 6 年前
Sometimes I feel like we are living in the wrong timeline.<p>In the right timeline, a deeply flawed language like JavaScript would never have been successful and we would use a decent application delivery mechanism that is platform-sensitive and not a hypertext document browser with a document model unsuitable for interactive apps.<p>But here we are: Never bet against JavaScript
评论 #19529762 未加载
评论 #19529754 未加载