From: Stefan Weiss on
On 11/05/10 19:34, Dr J R Stockton wrote:
> In comp.lang.javascript message <ab37b500-1b97-450c-9498-badd643ac361(a)j3
> 5g2000yqm.googlegroups.com>, Sun, 9 May 2010 20:02:32, nick
> <nick___(a)fastmail.fm> posted:
>>What's the "best" way to determine if a variable is defined?
>
> I don't recall any problem in testing X for the value undefined by using
>
> var U
> // ...
> if (X==U) ...
>
> although one must remember not to define U.

.... and to use the strict comparison operator.

> It was a design fault to give the language an undefined type and an
> undefined value, since it is then unnecessarily difficult to talk about
> it in English. Instead, non-words should have been used - "taghairm"
> would nearly serve; "trygdyl" would do. All who know English reasonably
> well will understand that those are not English words.
>
> One cannot test directly whether the variable 'akwidukt' has been
> declared, since a simple reference to it will give an error. But
> 'window.akwidukt' is merely 'undefined' if 'akwidukt' has not been
> defined.

Those are perfectly cromulent words which could embiggen our awkward
language. You should tell the Harmony people about your idea.


--
kwyjibo
From: "Michael Haufe ("TNO")" on
On May 9, 10:02 pm, nick <nick...(a)fastmail.fm> wrote:
> What's the "best" way to determine if a variable is defined?

foo in this //throws when foo is undefined
From: Ry Nohryb on
On May 12, 3:34 am, "Michael Haufe (\"TNO\")"
<t...(a)thenewobjective.com> wrote:
> On May 9, 10:02 pm, nick <nick...(a)fastmail.fm> wrote:
>
> > What's the "best" way to determine if a variable is defined?
>
> foo in this //throws when foo is undefined

"foo" in this doesn't.
--
Jorge.
From: Dr J R Stockton on
In comp.lang.javascript message <5dmdnU-R8ZcDbHTWnZ2dnUVZ8ludnZ2d(a)gigane
ws.com>, Wed, 12 May 2010 02:09:01, Stefan Weiss <krewecherl(a)gmail.com>
posted:

>On 11/05/10 19:34, Dr J R Stockton wrote:
>> In comp.lang.javascript message <ab37b500-1b97-450c-9498-badd643ac361(a)j3
>> 5g2000yqm.googlegroups.com>, Sun, 9 May 2010 20:02:32, nick
>> <nick___(a)fastmail.fm> posted:
>>>What's the "best" way to determine if a variable is defined?
>>
>> I don't recall any problem in testing X for the value undefined by using
>>
>> var U
>> // ...
>> if (X==U) ...
>>
>> although one must remember not to define U.
>
>... and to use the strict comparison operator.

Is that needed if X cannot be null ?

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
From: Stefan Weiss on
On 13/05/10 18:00, Dr J R Stockton wrote:
> In comp.lang.javascript message <5dmdnU-R8ZcDbHTWnZ2dnUVZ8ludnZ2d(a)gigane
> ws.com>, Wed, 12 May 2010 02:09:01, Stefan Weiss <krewecherl(a)gmail.com>
> posted:
>
>>On 11/05/10 19:34, Dr J R Stockton wrote:
>>> In comp.lang.javascript message <ab37b500-1b97-450c-9498-badd643ac361(a)j3
>>> 5g2000yqm.googlegroups.com>, Sun, 9 May 2010 20:02:32, nick
>>> <nick___(a)fastmail.fm> posted:
>>>>What's the "best" way to determine if a variable is defined?
>>>
>>> I don't recall any problem in testing X for the value undefined by using
>>>
>>> var U
>>> // ...
>>> if (X==U) ...
>>>
>>> although one must remember not to define U.
>>
>>... and to use the strict comparison operator.
>
> Is that needed if X cannot be null ?

No, but that wasn't mentioned anywhere by the OP.


--
stefan