HighDots Forums  

how to determine var existence

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss how to determine var existence in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ken Murphy
 
Posts: n/a

Default how to determine var existence - 11-04-2005 , 01:13 PM






I would like to be able to do this:

curVarGood = 'YYYNNNY'

var lcVar = 'curVarGood'
-OR-
var lcVar = 'curVarBad'

if typeof(eval(lcVar)) == 'undefined'
lcResult = 'NNNNNNN' //var undefined
else
lcResult = eval(lcVar) //good var to process

but I get an undefined error on the first eval(), which is what I am trying
to check for.

I know the syntax above may not be exactly correct - I have tried lots of
stuff.

I just need to know the correct commands.

Thanks.....KM




Reply With Quote
  #2  
Old   
Kimmo Laine
 
Posts: n/a

Default Re: how to determine var existence - 11-05-2005 , 01:37 AM






"Ken Murphy" <ken (AT) murphysoftware (DOT) net> kirjoitti
viestissä:4-ydnak95fbGLvbenZ2dnUVZ_t2dnZ2d (AT) comcast (DOT) com...
Quote:
I would like to be able to do this:

curVarGood = 'YYYNNNY'

var lcVar = 'curVarGood'
-OR-
var lcVar = 'curVarBad'

if typeof(eval(lcVar)) == 'undefined'
lcResult = 'NNNNNNN' //var undefined
else
lcResult = eval(lcVar) //good var to process

but I get an undefined error on the first eval(), which is what I am
trying to check for.

I know the syntax above may not be exactly correct - I have tried lots of
stuff.

I just need to know the correct commands.

I'd suggest something like this:

try {
lcResult = eval(lcVar);
} catch(e) {
lcResult = 'NNNNNNN';
}



--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <antaatulla.sikanautaa (AT) gmail (DOT) com.NOSPAM.invalid>




Reply With Quote
  #3  
Old   
Jasen Betts
 
Posts: n/a

Default Re: how to determine var existence - 12-20-2005 , 03:19 AM



On 2005-11-05, Kimmo Laine <antaatulla.sikanautaa (AT) gmail (DOT) com.NOSPAM.invalid> wrote:
Quote:
"Ken Murphy" <ken (AT) murphysoftware (DOT) net> kirjoitti
viestissä:4-ydnak95fbGLvbenZ2dnUVZ_t2dnZ2d (AT) comcast (DOT) com...
I would like to be able to do this:

curVarGood = 'YYYNNNY'

var lcVar = 'curVarGood'
-OR-
var lcVar = 'curVarBad'

if typeof(eval(lcVar)) == 'undefined'
lcResult = 'NNNNNNN' //var undefined
else
lcResult = eval(lcVar) //good var to process

try it inside-out. like this.

if( eval("typeof("+lcVar+")") == 'undefined' )


etc.


Bye.
Jasen


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.