TypeScript Null and Undefined

Type null undefined


Null is an object type that represent the null, nothing, empty or non-existent value. You can declare a variable with null value. Null is a special keyword.


        let variable_null =null;
        console.log(variable_null); // output : null


Undefined means a variable has been declared without assign any value.


        let variable_undefined;
        console.log(variable_undefined);   // output : undefined

        console.log(typeof undefined);     // output : undefined


You can also set the undefined value explicitly.


        let variable_undefined = undefined;

        console.log(variable_undefined);   // output : undefined

null vs undefined

Null Undefined

Value is assigned

Value is not assigned

typeof object

typeof undefined

console.log(undefined ==null);


console.log(undefined ===null) //false;