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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

BigInt is finally here in ES2020

21 点作者 AmruthPillai超过 4 年前

3 条评论

Lx1oG-AWb6h_ZG0超过 4 年前
&gt; Using JSON.stringify() with any BigInt value will raise a TypeError as BigInt values aren&#x27;t serialized in JSON by default. However, you can implement your own toJSON method if needed<p>Sorry, why exactly can’t they also define the json.parse&#x2F;stringify behavior of bigints? JSON was initially derived from JavaScript, so it seems a bit weird that a new ES standard can’t interoperate with json
评论 #26300361 未加载
评论 #26311447 未加载
评论 #26310675 未加载
评论 #26311359 未加载
MaxBarraclough超过 4 年前
&gt; BigInt is a built-in object that provides a way to represent whole numbers larger than 2^53 - 1, which is the largest number JavaScript can reliably represent with the Number primitive and represented by the Number.MAX_SAFE_INTEGER constant.<p>Isn&#x27;t this wrong? JavaScript&#x27;s Number type can represent some integers vastly greater than this. [0] What&#x27;s special about Number.MAX_SAFE_INTEGER, if I understand correctly, is that it&#x27;s the smallest integer such that (Number.MAX_SAFE_INTEGER + 1) is not guaranteed to be represented faithfully by the Number type.<p>Given the topic, I don&#x27;t think I&#x27;m being pedantic.<p><i>edit</i> On second thought, I could well be mistaken. The definition of JavaScript&#x27;s Number type might be such that no guarantees are made about which integers greater than Number.MAX_SAFE_INTEGER can be represented exactly.<p><i>edit 2</i> Nope, Number.MAX_VALUE is defined to be an integer. [0] Which is to say, the largest whole number that can be represented is Number.MAX_VALUE, <i>not</i> Number.MAX_SAFE_INTEGER. Of course, it&#x27;s not the case that Number is guaranteed to be able to exactly represent all non-negative integers less than Number.MAX_VALUE, but that isn&#x27;t the same thing. The article appears to get this wrong.<p>[0] <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Number&#x2F;MAX_VALUE" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Refe...</a>
评论 #26304877 未加载
评论 #26302747 未加载
评论 #26302540 未加载
JoBrad超过 4 年前
Really sucks that they didn’t make it compatible with Math functions and other Number types. Even more type checking. Python did the same thing with Decimal at first, and it wasn’t fun to accommodate.