We're learning TypeScript and while declaring a variable we tried to specify its type too like this
let a: number = 5;
let b: boolean;
let c: string;
let d: any;
let e: number[] = [1, 2, 3, 4, 5];
let f: any[] = [true, 'foo', 4.09, []];
let g: null;
These any and null were new to us, we were able to understand the concept of any, but it's confusing with null. This is the first time we are hearing about null as a data type, we've heard null as a value in Java. The really confusing thing is why someone would need a data type as null.
In Java, we declare variables as
int a = 0;
double b = 0.0;
char c = 'c';
String x = "abc";
But if null is a data type, it will like this
null a;
We're finding it difficult to understand this concept! If null is assigned to a variable its cool, nothing is there that's it, but what is the purpose of having null as a data type? So we looked at some websites
Data types in TypeScript - here its says It is used when an object does not have any value, but does it mean assign null if an object doesn't have a value or specify null as a type to those objects which don't have any value?
Here in How to declare a type as nullable in TypeScript? and TypeScript: Define type that can be bool or null, the discussion was about assigning/returning null to some variable.
So can anybody help us with clearing this concept of null being used as a data type?
 
    