From 2e4745b189021c460e53db42d406a66793c61233 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 31 Jul 2018 16:58:36 +0000 Subject: [PATCH] update null examples --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index a8720f7..0183b81 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,23 @@ null === store.get('non-existant-key'); The special case of `null` as `"null"`, aka `"\"null\""`: +``` +typeof null // object +typeof "null" // string +typeof "\"null\"" // string +``` + `null`, and `"null"` both parse as `null` the "object", instead of one being the string (which would be `"\"null\""`). +``` +JSON.parse(null) // null (object) +JSON.parse("null") // null (object) +JSON.parse("\"null\"") // 'null' (string) +``` + Objects containing `null`, however, parse as expected `{ "foo": null, "bar": "null" }` will parse as `foo` being `null` but `bar` being `"null"`, much unlike the value `"null"` being parsed on its own. + +``` +JSON.parse('{ "foo": null }') // { foo: null } +JSON.parse('{ "foo": "null" }') // { foo: 'null' } +``` \ No newline at end of file