为了账号安全,请及时绑定邮箱和手机立即绑定

JSON.stringify(NaN)为什么等于null

JSON.stringify(NaN)为什么等于null

九州编程 2019-03-14 21:57:45
JSON.stringify(NaN)"null"JSON.stringify([NaN])"[null]"JSON.stringify(undefined)undefinedJSON.stringify(null)"null"JSON.stringify([undefined])"[null]"求解释原理
查看完整描述

2 回答

?
跃然一笑

TA贡献1826条经验 获得超6个赞

ecma-262 规范文档 的角度解释标题的问题就非常简单。

直接看为什么 JSON.stringify(NaN) => "null"

NOTE 4
Finite numbers are stringified as if by calling ToString(number). NaN and Infinity regardless of sign are represented as the String null.

NaN 会被 当成字符串 null

为什么 
JSON.stringify(undefined) => undefined
JSON.stringify([undefined]) => "[null]"

NOTE 5
Values that do not have a JSON representation (such as undefined and functions) do not produce a String. Instead they produce the undefined value. In arrays these values are represented as the String null


查看完整回答
反对 回复 2019-03-14
?
忽然笑

TA贡献1806条经验 获得超5个赞

undefined 直接返回 undefined ; 在数组中,就被当成 字符串null;

查看完整回答
反对 回复 2019-03-14
  • 2 回答
  • 0 关注
  • 1076 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号