September 24, 2006

Detecting Undefined Variables in JavaScript

This pops up every so often so I thought I’d dedicate a post to it. JavaScript has no “isset” function. Instead, your best bet is to use the following:

if((typeof theVariable) == ‘undefined’)

Filed under: Javascript, Programming — Michi @ 2:01 am

Share this

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Reddit
  • StumbleUpon
  • del.icio.us
  • description
  • Technorati
  • Slashdot
  • co.mments
  • NewsVine

Related

What is the difference between the write function and the innerHTML property? There is a huge difference. What happens to any JavaScript you import using these methods? It's more complicated than you think. The write() function (as in, document.write), writes...
Today's crazy error of the day is: Fatal error: Call to undefined function preg_match() ... Wahoo! A built in function being undefined! So how's this possible? It seems that if you reinstall PHP without compiling in PCRE (Perl Compatible...

No Comments »

TrackBack URI | Blog RSS | Comment RSS

No comments yet.

What do you think?