Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  166] [ 7]  / answers: 1 / hits: 22570  / 15 Years ago, tue, june 30, 2009, 12:00:00

I have code that is wrapped in try/catch block.
I use typeof to find out if a variable is defined:



if (typeof (var) == 'string') { 
//the string is defined
}


However, using this in a try/catch block, jumps to the catch part instead of doing what it is suppoed to do (do something with the string if its defined).



How can I check if a variable is defined without activating an exception?


More From » try-catch

 Answers
7

'var' is not a valid variable name - it's a keyword.



Apart from that, what you have should be correct.


[#99216] Thursday, June 25, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carlo

Total Points: 705
Total Questions: 87
Total Answers: 101

Location: Indonesia
Member since Wed, Jul 7, 2021
3 Years ago
;