null
null is a keyword in javascript,which is a special value that indicates no value,a value that represents no object, if a variable holds the value null,it means that the variable contains nothing.
In the last topic,I said that when null value converts to boolean ,it is false,to numeric ,it's 0,and when used in a string context,it converts to "null"(it is a string context);
someting examples of a null value,we use document.getElementById("testID"),if the form does not contain a control which id is named "testID",the document.getElementById("testID") will return null.


var nullVar = document.getElementById("ttt");
alert(Number(nullVar));//as number,alert 0
alert(Boolean(nullVar)); //as boolean,alert false
alert(nullVar);//as string,//alert null
}
in the above code ,document.getElementById("ttt") return null.
you can't use any properties of null value,in the above value,if you use nullVar.value or nullValue.toString(),there will be a error occured.so it does in C#(in C# ,if we uses properties of a null object,a error occurs too).in other word,null values noting.
undefined
undefined is returned when you use either a variable that has been declared but never had a value assigned to it or an object property that does not exist.
some data conversions are in the eg. code as follows:


var undfVar
alert(undfVar); //as string,alert undefined
alert(Boolean(undfVar)); //as boolean ,alert false
alert(Number(undfVar));//as number ,alert NaN
}
in this code,why undfVar is undefined ,because it was declared but never had a value assigned to it,so it is undefined.
in other way,if we use the object property that does not exist, it returns undefined too,just eg.
(there is a input control in the body of current form)
var proUndf = document.getElementById("existInput");
alert(proUndf.Alex);
}
proUndf represents a exist input control,as we know,input does not have a property that is named Alex;so proUndf.Alex returns undefined;
comparison between null and undefined
Although null and undefined value are distinct,the ==operator considers them equal to each other;if we truely distinguish between a null value and an undefined value, we can use === operator or typeof function,eg.


var proUndf = document.getElementById("existInput");
alert(proUndf.Alex == null); //alert true
alert(proUndf.Alex === null); //alert false
alert(typeof(proUndf.Alex) === typeof(null)); //alert false
}
undefined is not a keyword in javascript while null is.
var
var is used to define a vailable,any types,because javascript is untyped (on the other hand ,C# is typed),I do not want to discuss the details of var.just want some specials.
in javascript we can also declare a varialbe without var.when you assign a value to a variable that not be declared with var,javascript will implicitly declare that variable and assign the value to it,but,the implicitly declared varialbe will be treated as a global variable,even if it is just used in a function,eg;


myName = "Alex";
alert(myName); //alert Alex
test();
alert(myName);//alert AlexHe,it has been changed by the function of test(),
}
function test()
{
alert(myName); //alert Alex
myName = "AlexHe";
}
so we must be in habit of using var to declare a varialble whether which is a global variable or a local variable.