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
添加回答
举报
0/150
提交
取消