On Fri, Feb 4, 2011 at 10:54 PM, mcot <[email protected]> wrote:

> Hi.  I am still reading up on this but here are some more tests I have
> run:
>
> console.log(typeof(foo) === 'undefined');       // true  -- doesn't raise
> reference error.
> foo;                                                            //
> reference error even without the call to console.log
>

That's because `typeof` operator never calls `GetValue` on its operand
(`GetValue` is what throws ReferenceError, as explained earlier). This was
done specifically so that `typeof` can be applied to undeclared identifiers
(and return "undefined" rather than throw an exception). `foo` in second
statement, however, does get passed through `GetValue` — as any other
ExpressionStatement; hence ReferenceError.

[...]

-- 
kangax

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to