According to ECMAScript there are null
and undefined
datatypes apart from others.
But recently I got to see something called empty
. Let's regenerate it first (I'll go from basic):
let a = new Array()
//Returns []
length=0
let b = new Array(3)
//Returns [empty*3]
length=3
let c = new Array(3).fill()
//Return [undefined,undefined,undefined]
length=3
Now, what? See all the elements defined are undefined, which they should be
a[0]=undefined
b[0]=undefined
c[0]=undefined
Main thing:
If suppose add an element into c
at position 5 i.e a[5]=4
then c
will be [undefined,undefined,undefined,empty,4]
What is this empty thing in between? And if everything is same what is the difference in starting initialization of b
and c
( I'm talking about [empty*3]
& [undefined,undefined,undefined]
).
The Answer suggested [here]: What's the difference between empty items in a JavaScrip array and undefined? Doesn't explains the properly about what exactly it is. Yes it can't be undefined
as undefined
is a value but what about null
and if not null
why empty is not a data-type?