{"id":522,"date":"2025-12-05T19:32:50","date_gmt":"2025-12-05T11:32:50","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=522"},"modified":"2025-12-05T19:32:50","modified_gmt":"2025-12-05T11:32:50","slug":"javascript%e4%bd%bf%e7%94%a8bigint%e5%a4%84%e7%90%86%e8%b6%85%e5%a4%a7%e6%95%b0%e5%80%bc%e5%85%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/05\/javascript%e4%bd%bf%e7%94%a8bigint%e5%a4%84%e7%90%86%e8%b6%85%e5%a4%a7%e6%95%b0%e5%80%bc%e5%85%a8%e6%8c%87%e5%8d%97\/","title":{"rendered":"JavaScript\u4f7f\u7528BigInt\u5904\u7406\u8d85\u5927\u6570\u503c\u5168\u6307\u5357"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd <strong>2025 \u6700\u65b0\u7248\u672c\u3001\u542b\u793a\u4f8b\u4ee3\u7801\u3001\u6df1\u5165\u539f\u7406\u5206\u6790<\/strong> \u7684<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u300aJavaScript \u4f7f\u7528 BigInt \u5904\u7406\u8d85\u5927\u6570\u503c\u5168\u6307\u5357\u300b<\/h1>\n\n\n\n<p>BigInt \u662f\u5904\u7406 <strong>\u8d85\u8fc7 Number \u5b89\u5168\u8303\u56f4\u7684\u5927\u6570\u8ba1\u7b97<\/strong> \u7684\u6700\u4f73\u65b9\u5f0f\uff0c\u7279\u522b\u9002\u5408\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u91d1\u878d\u7cfb\u7edf\uff08\u91d1\u989d\u7cbe\u786e\u8ba1\u7b97\uff09<\/li>\n\n\n\n<li>\u52a0\u5bc6\u7b97\u6cd5<\/li>\n\n\n\n<li>\u5927\u6574\u6570\u79d1\u5b66\u8ba1\u7b97<\/li>\n\n\n\n<li>\u5904\u7406\u8d85\u8fc7 64 \u4f4d\u6574\u6570\u7684 ID\uff08\u5982\u96ea\u82b1\u7b97\u6cd5 ID\uff09<\/li>\n\n\n\n<li>\u7cbe\u786e\u5927\u6570\u76f8\u52a0 \/ \u76f8\u51cf \/ \u76f8\u4e58 \/ \u76f8\u9664<\/li>\n<\/ul>\n\n\n\n<p>\u672c\u6307\u5357\u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff0c\u5168\u90e8\u641e\u61c2\uff01<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udd25 \u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981 BigInt\uff1f<\/h1>\n\n\n\n<p>JavaScript \u539f\u751f <code>Number<\/code> \u4f7f\u7528 <strong>\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff0864 \u4f4d\uff09<\/strong>\uff0c\u6700\u5927\u5b89\u5168\u6574\u6570\u4e3a\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nNumber.MAX_SAFE_INTEGER === 9007199254740991\n\n<\/pre><\/div>\n\n\n<p>\u8d85\u8fc7\u8fd9\u4e2a\u6570\u4f1a\u53d1\u751f <strong>\u7cbe\u5ea6\u4e22\u5931<\/strong>\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n9007199254740991 + 1   \/\/ 9007199254740992\n9007199254740991 + 2   \/\/ 9007199254740992 \u274c \u7cbe\u5ea6\u51fa\u9519\uff01\n\n<\/pre><\/div>\n\n\n<p>\u6240\u4ee5\u5927\u578b\u9879\u76ee\u5e38\u89c1 bug\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u91d1\u989d\u4e22\u5931\u7cbe\u5ea6<\/li>\n\n\n\n<li>\u540e\u7aef\u96ea\u82b1 ID \u88ab\u524d\u7aef\u622a\u65ad<\/li>\n\n\n\n<li>\u5927\u6570\u8ba1\u7b97\u9519\u8bef<\/li>\n<\/ul>\n\n\n\n<p>\ud83d\udc49 <strong>\u89e3\u51b3\u65b9\u6848\uff1aBigInt<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\ude80 \u4e8c\u3001BigInt \u7684\u4f7f\u7528\u65b9\u6cd5<\/h1>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u521b\u5efa BigInt<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u2460 \u4f7f\u7528 <code>n<\/code> \u540e\u7f00<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst big = 123456789123456789n;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2461 \u4f7f\u7528 BigInt() \u51fd\u6570<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst big = BigInt(&quot;123456789123456789&quot;);\n\n<\/pre><\/div>\n\n\n<p>\u4e24\u8005\u4f5c\u7528\u76f8\u540c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\ude80 \u4e09\u3001BigInt \u652f\u6301\u7684\u8fd0\u7b97\u7b26<\/h1>\n\n\n\n<p>\u6240\u6709\u5e38\u7528\u8fd0\u7b97\u90fd\u53ef\u7528\uff1a<br>\u52a0\u3001\u51cf\u3001\u4e58\u3001\u9664\u3001\u5e42\u3001\u53d6\u6a21<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2714 \u52a0\u6cd5<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n10n + 20n \/\/ 30n\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u2714 \u51cf\u6cd5<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n30n - 10n \/\/ 20n\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u2714 \u4e58\u6cd5<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n10n * 20n \/\/ 200n\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u2714 \u9664\u6cd5\uff08\u5411\u4e0b\u53d6\u6574\uff01\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n7n \/ 2n   \/\/ 3n   \uff08\u4e0d\u4f1a\u4ea7\u751f\u5c0f\u6570\uff09\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u2714 \u5e42\u8fd0\u7b97<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n2n ** 100n\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u2714 \u53d6\u6a21<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n10n % 3n \/\/ 1n\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udea7 \u56db\u3001BigInt \u7684\u4e25\u683c\u9650\u5236\uff08\u5fc5\u987b\u8bb0\u4f4f \u2757\uff09<\/h1>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u274c BigInt \u4e0d\u80fd\u548c Number \u6df7\u5408\u8fd0\u7b97<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n10n + 1 \/\/ \u274c TypeError\n\n<\/pre><\/div>\n\n\n<p>\u5fc5\u987b\u663e\u5f0f\u8f6c\u6362\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n10n + BigInt(1)  \/\/ \u2714\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u274c BigInt \u4e0d\u652f\u6301\u6d6e\u70b9\u6570<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nBigInt(1.23) \/\/ \u274c \u62a5\u9519\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u274c BigInt \/ Number \u7684\u6bd4\u8f83\u89c4\u5219\u4e0d\u540c<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n10n === 10 \/\/ false\n10n == 10  \/\/ true\uff08\u503c\u76f8\u7b49\uff09\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udfaf \u4e94\u3001BigInt \u7684\u7c7b\u578b\u5224\u65ad<\/h1>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ntypeof 123n  \/\/ &quot;bigint&quot;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udd27 \u516d\u3001BigInt \u4e0e Number \u7684\u8f6c\u6362<\/h1>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">BigInt \u279c Number<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nNumber(123n) \/\/ 123\n\n<\/pre><\/div>\n\n\n<p>\u26a0\ufe0f \u5982\u679c BigInt \u975e\u5e38\u5927\uff0c\u4f1a\u6ea2\u51fa\uff01<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Number \u279c BigInt<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nBigInt(123)  \/\/ 123n\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\uddee \u4e03\u3001BigInt \u5b9e\u6218\u793a\u4f8b<\/h1>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u793a\u4f8b 1\uff1a\u5904\u7406\u8d85\u5927\u8ba2\u5355\u7f16\u53f7\uff08\u96ea\u82b1 ID\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst id = BigInt(&quot;9223372036854775808&quot;);\nconsole.log(id + 2n);\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u793a\u4f8b 2\uff1a\u7cbe\u786e\u91d1\u989d\u8ba1\u7b97\uff08\u907f\u514d\u6d6e\u70b9\u8bef\u5dee\uff09<\/h2>\n\n\n\n<p>\u4f20\u7edf\u5199\u6cd5\u6d6e\u70b9\u8bef\u5dee\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n0.1 + 0.2 \/\/ 0.30000000000000004 \u274c\n\n<\/pre><\/div>\n\n\n<p>BigInt \u91d1\u989d\uff1a\u4ee5\u5206\u4e3a\u5355\u4f4d\uff08\u5f3a\u70c8\u63a8\u8350\uff09<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst a = 10n;  \/\/ 10 \u5206\nconst b = 20n;  \/\/ 20 \u5206\nconst c = a + b; \/\/ 30n \u5206\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u793a\u4f8b 3\uff1a\u8ba1\u7b97\u8d85\u5927\u9636\u4e58\uff081000!\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfunction factorial(n) {\n  let result = 1n;\n  for (let i = 1n; i &amp;lt;= n; i++) {\n    result *= i;\n  }\n  return result;\n}\n\nconsole.log(factorial(1000n));\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u793a\u4f8b 4\uff1a\u5927\u6574\u6570\u5e42\u8ba1\u7b97\uff08\u52a0\u5bc6\u7b97\u6cd5\u5e38\u7528\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst result = 123456789n ** 50n;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udca1 \u516b\u3001BigInt \u4e0e JSON \u7684\u517c\u5bb9\u95ee\u9898<\/h1>\n\n\n\n<p>JSON <strong>\u4e0d\u652f\u6301 BigInt<\/strong>\uff01<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nJSON.stringify(123n) \/\/ \u274c \u62a5\u9519\n\n<\/pre><\/div>\n\n\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5 1\uff1a\u5e8f\u5217\u5316\u4e3a\u5b57\u7b26\u4e32<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nJSON.stringify({ id: &quot;123456789123456789&quot; });\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5 2\uff1a\u81ea\u5b9a\u4e49 JSON \u66ff\u4ee3\u65b9\u6848\uff08\u63a8\u8350\uff09<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst obj = { id: 123456789123456789n };\n\nconst json = JSON.stringify(obj, (_, v) =&gt;\n  typeof v === &quot;bigint&quot; ? v.toString() : v\n);\n\nconsole.log(json);  \/\/ {&quot;id&quot;:&quot;123456789123456789&quot;}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udccc \u4e5d\u3001BigInt \u7684\u6700\u4f73\u5b9e\u8df5\u603b\u7ed3<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u573a\u666f<\/th><th>BigInt \u662f\u5426\u9002\u5408\uff1f<\/th><\/tr><\/thead><tbody><tr><td>\u8d85\u5927 ID\uff08\u96ea\u82b1 ID\uff09<\/td><td>\u2714 \u5f3a\u70c8\u63a8\u8350<\/td><\/tr><tr><td>\u91d1\u989d\u8fd0\u7b97\uff08\u4f7f\u7528\u5206\uff09<\/td><td>\u2714 \u65e0\u8bef\u5dee<\/td><\/tr><tr><td>\u79d1\u5b66\u8ba1\u7b97<\/td><td>\u2714<\/td><\/tr><tr><td>\u52a0\u5bc6\u7b97\u6cd5<\/td><td>\u2714<\/td><\/tr><tr><td>JSON \u4ea4\u4e92<\/td><td>\u274c \u5fc5\u987b\u8f6c\u6362<\/td><\/tr><tr><td>\u6d6e\u70b9\u6570\u8ba1\u7b97<\/td><td>\u274c \u4e0d\u652f\u6301\u5c0f\u6570<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd 2025 \u6700\u65b0\u7248\u672c\u3001\u542b\u793a\u4f8b\u4ee3\u7801\u3001\u6df1\u5165\u539f\u7406\u5206\u6790 \u7684 \u300aJavaScr&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/05\/javascript%e4%bd%bf%e7%94%a8bigint%e5%a4%84%e7%90%86%e8%b6%85%e5%a4%a7%e6%95%b0%e5%80%bc%e5%85%a8%e6%8c%87%e5%8d%97\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"class_list":["post-522","post","type-post","status-publish","format-standard","hentry","category-javascript"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=522"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/522\/revisions"}],"predecessor-version":[{"id":523,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/522\/revisions\/523"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}