'void' as a value

David Bruant bruant.d at gmail.com
Mon Sep 9 02:51:51 PDT 2013

Le 09/09/2013 11:41, Claude Pache a écrit :
> Le 9 sept. 2013 à 10:35, David Bruant <bruant.d at gmail.com> a écrit :
>> Le 08/09/2013 21:39, Brendan Eich a écrit :
>>> In no case does anyone that I've spoken to, on TC39 or anywhere else around this planet, want *yet another* bottom type and singleton value a la null and undefined. No one. Those who speak Spanish and nearby languages tend to say "¡Basta!" -- I'm not kidding :-|.
>> Two values are already arguably (!) a regrettable feature https://github.com/DavidBruant/ECMAScript-regrets/issues/26
>> David
> For me, it is a excellent feature, if we get the correct semantic:
The issue has a lengthy debate too ;-)

> * `undefined` means "no value", or "nothing";
> * `null` means "empty value", or (well) "null".
> Practical usefulness:
> * ES5: JSON stringification of object: `null` means `null`, and `undefined` means "no value, don't include the corresponding key".
> * ES6: default values in function arguments (and maybe destructuring assignment?): `null` means `null`, and `undefined` means "no value, take the default".
This is all after-the-fact justification. I understand the usefulness 
made of this feature now that we have the 2 values, but I wonder if 
given the choice to start over a newJS would be designed with 2 such values.

Among the nonsense of undefined-as-a-value:
     var wm = new WeakMap();
     var o = {};
     console.log(wm.has(o), wm.get(o)); // false, undefined
     wm.set(o, undefined);
     console.log(wm.has(o), wm.get(o)); // true, undefined

So we can "define" a weakmap entry with the "undefined" value. That's 
how objects work, so that can't be changed. I wonder what has been 
gained for weakmaps. For sure, some memory is wasted to keep the "has" 
boolean working.
WeakMaps would feel simpler if wm.set(o, undefined) was an equivalent 
for wm.delete... to me at least...


More information about the es-discuss mailing list