Conditional checking for uninitailized, undefined variable in javascript

If you’re working in php, its very simple to check a variable if it is initailized or has a value but in javascript, its a bit tricky if you didn’t handle this yet. But if you’re a javascript guy, it might be supper simple for you. Anyway, I’m sharing here the way I did to check an undefined variable in javascript. Just try following code –

if (typeof myVar == 'undefined')

I thought, sharing this will be helpful to others. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.