Friday, June 5, 2009

undefined and null are same in Javascript with sample code

undefined is a global property (variable) with a constant value. Javascript treats undefined as being equal to null.
Sample code
<html>
<body>

<script type="text/javascript">
var test;
if (test==null)
{
alert("null");
}

if (test==undefined)
{
alert("undefined");
}
</script>

</body>
</html>

No comments:

Post a Comment