I was just playing around with JavaScript and got stuck with a simple program.
I declared an array in JavaScript like
var a = [0, 1, 2];
An array is a continuous collection of data. Say if you have a value at index 1
and index 10
, the rest will be filled by undefined
.
You can't create an array with empty values. 'Empty in your sense', is not undefined or null, it's empty :)
That continuous data is undefined means default assignment in JavaScript.
Say if you defined a variable,
var X;
console.log(X) //Undefined
it's not null
. null
is a user explicitly specifying a way to tell there is an empty data, and undefined
is the JavaScript engine way.