Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Difference between 'null' and 'undefined'

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 149
    Comment on it

    The difference between undefined and null is as follows,

    1-When we declare any variable and we do not give it a value then it will have the value undefined.Undefined is a type all to itself

    2- We can declare a variable and can set it to null.JavaScript do not set anything to null, only we can declare any variable to null. When you're debugging the code then you can see that anything that is set to null is of your own doing and not JavaScript.

    We can also compare a variable which is undefined to null and the condition will be true. For Example:

    undefined == null
    null == undefined

    Undefined Example -:

    var a = [ 'a', 'b', 'c' ];
    delete a[1];
    for (var i = 0; i < a.length; i++)
    WScript.Echo((i+".) "+a[i]);

    The output for the above script is:

    0.) a
    1.) undefined
    2.) c

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: