Welcome to WebmasterWorld Guest from 54.196.117.47

Forum Moderators: open

Message Too Old, No Replies

Javascript & checking empty variables

     
10:59 pm on Feb 12, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:May 3, 2001
posts:365
votes: 0


Hi All.

Quick question. How do I check exactly if a variable is empty in javascript?

Or more closely a variable passed to a function?

4:02 pm on Feb 13, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 20, 2002
posts:3732
votes: 0


So is the variable null?

<script>
var test;
if(test!=null){
document.write("exists!");
}else{
document.write("Nope");
}
</script>

You can check for undefined this way:

<script>
var test=1;
if(typeof(test)=="undefined"){
document.write("undefined");
}else{
document.write("Exists");
}
</script>

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members