ES6 doesn't need opt-in

John J Barton johnjbarton at
Sun Jan 1 08:52:56 PST 2012

On Sun, Jan 1, 2012 at 5:12 AM, David Bruant <bruant.d at> wrote:

>  Le 01/01/2012 06:12, John J Barton a écrit :
> On Sat, Dec 31, 2011 at 7:53 PM, Axel Rauschmayer <axel at>wrote:
>>  1. Checking whether a variable has been declared.
>>     Problematic: verbose and conflated with checking for a declared
>> variable having the value `undefined`.
>>     Better: a dedicated operator or predicate for performing this check.
>  Sorry, I don't think anyone checks if a is variable declared. You just
> look at the source code.
> I have read code where people checked variable existence in global code.
> Typeof prevents a ReferenceError if the variable is not declared.
> Having been used to do it in global code (where you can't always "read the
> code"), or just reading it somewhere, people reproduce within a function.

Maybe I am confused. Here is what I was imagining:
  var w = 1;  // w is declared and defined. typeof gives 'number'
  var x;  // x is declared, but is undefined. typeof gives 'undefined'
  y = 4; // y is not declared, is a global.    typeof gives 'number'
           // z is not declared                     typeof gives 'undefined.

So how can I check to see that y and z are not declared?

  var b;
  if (typeof x !== 'undefined') b = x

I don't get a ReferenceError. What I am I missing?

> I agree that there are a lot of bad practices in here, but some people do
> do it.
> Moreover, the concept of static scoping and "just look at the code to see
> if a variable is declared" is not that obvious for newcomers to the
> language or newcomers to programming.

I guess newcomers won't understand typeof either ;-).


> David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list