On 08.01.2009, at 14:37, Sven Helmberger wrote:
Noah Slater schrieb:
On Thu, Jan 08, 2009 at 02:21:27PM +0100, Sven Helmberger wrote:
Shouldn't couchdb treat null and undefined values the same?
Well, a "null" value is a way of saying "this doesn't have a value" but when something is undefined, you don't know if it has a value or not. The difference
is subtle, but it's an important one.
I am aware that there is in fact a difference in javascript, but since there is no "undefined" keyword for JSON, I would argue that that should
not be the case for JSON and couchdb.
Well, an undefined value is by definition, undefined.

in javascript, "undefined" is a keyword for an undefined value. exactly the value that doc._rev has when doc has no property _rev.

Technically, and nitpickingly, that's not the value doc._rev has, because doc._rev does not exist ;) It's the value returned by Javascript when you access a property that doesn't exist.

The absence of an "undefined" keyword leads me to the expectation that for JSON {} should be the same as {"foo":null}.

No, "undefined" means that an object has no such property, whereas {"foo":null} clearly *has* a "foo" property.

I'm not sure what problem you're trying to solve here. If you need to state that a JSON object doesn't have a property, simply omit it. No need for an invalid keyword.

Also note that "invalid" is not a keyword in Javascript either, it's the string value returned by `typeof somethingUndefined`.

Cheers,
--
Christopher Lenz
  cmlenz at gmx.de
  http://www.cmlenz.net/

Reply via email to