JAVASCRIPT: Difference between UNDEFINED and NULL

Javascript Undefined vs NULL

Many a times we often get confused on whats the difference between UNDEFINED and NULL.
undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value.
Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
Unassigned variables are initialized by JavaScript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.


Validating html tags in textbox – Cross site scripting

Following is the code to validate any textbox or input text against html tags.

//source and args are required if calling from custom validator in else its not required
function htmlValidation(source,args) 
var re = /(<([^>]+)>)/gi;

if (document.getElementById(’<%=TextBox2.ClientID%>’).value.match(re)) {
document.getElementById(’<%=TextBox2.ClientID%>’).value = “”;
alert(’Invalid content’);
//args.IsValid = false; // you can use this if you are calling this from custom validator in
return false;
if (document.getElementById("textboxid").value.match(re)) {
document.getElementById("textboxid").value = “”;
alert(’Invalid content’);
return false;
return true;