Checking if a variable has anything in it is a common thing to do.  In JavaScript it can trip you up unless you understand the three types of empty variable:

Create a page called empty.html and put this in it to illustrate those three things:

function showEmptyVariables() {
    alert(aVariableNeverDefined);	// this line will stop execution as the variable does not exist
	    		
    var anUndefinedVariable;	// declared but nothing was ever put in it in it
    alert(anUndefinedVariable);	// this should display an alert saying undefined as there is nothing to display (but no error)
	    		
    var anEmptyVariable='';	// declared and nothing/empty is put into it
    alert(anEmptyVariable);	// this should show a blank (empty) alert
	    		
}
	    	
showEmptyVariables();

The first time you run it nothing will happen.  Open your error console to see why (make sure you understand and read the comments).  Then comment out the first alert line and try again.  Now you should get two successful alert messages.

Emptying a variable

If there is a variable which contains something and you want to empty it the temptation is to use fred=''.  It is empty now but the value still exists because it contains an empty value (technically it contains the null character which is 0 or 00000000 in ASCII and other character sets).  This matters when you use if statements to see if a variable is undefined, empty or contains something.  You will be doing that so make sure you understand the differences.

The code in scope.html illustrated this.  It checked for the type of the variable and if it was undefined (the variable) it said so.  This is different to the variable existing but the value not having been defined! 

This might help if you are still struggling but might not!  Create a new page called empty2.html and put this into it comparing the code and comments with empty.html:

function showEmpyVariables() {
	    		
    if(typeof aVariableNeverDefined!='undefined'){
        alert('aVariableNeverDefined is: '+aVariableNeverDefined);	// this will only run if the variable exists and has a defined value (which it does not)
    } else {
        alert('aVariableNeverDefined does not seem to be fully defined')
    }
	    		
	    		
    var anUndefinedVariable;	// declared but nothing in it
    if(typeof anUndefinedVariable!='undefined'){
        alert('anUndefinedVariable is: '+anUndefinedVariable);	// this will only run if the variable exists and has a defined value (which it does not)
    } else {
        alert('anUndefinedVariable does not seem to be fully defined')
    }
	    		
    var anEmptyVariable='';	// declared but nothing in it
    if(typeof anEmptyVariable!='undefined'){
        alert('anEmptyVariable is: '+anEmptyVariable);	// this will only run if the variable exists (which it does)
    } else {
        alert('anEmptyVariable does not seem to be fully defined')
    }
	    		
    anUndefinedVariable='';	// that variable was declared but now has a value (empty) so the results are different
    if(typeof anUndefinedVariable!='undefined'){
        alert('anUndefinedVariable is: '+anUndefinedVariable);	// this will only run if the variable exists and has a defined value (which it now does)
    } else {
        alert('anUndefinedVariable does not seem to be fully defined')
    }
	    		
    anUndefinedVariable=undefined;	// change the empty value to an undefined value
    alert('anUndefinedVariable is: '+anUndefinedVariable);	// if statement removed so you see the alert showin undefined
	    		
}
	    	
showEmpyVariables();

In JavaScript you cannot destroy a variable once it has been properly declared.