Why does null increase the length of an array, even if it represents an empty value?

When "null" is included in the elements of an array, it counts the length of the array. But β€œzero” should not mean any value. Then why is this happening?

var myArray = ["pizza", "burger", null];

var test = function (input) {
	return input.length;
};
document.write(test(myArray));
Run codeHide result
+4
source share
4 answers

A null value represents the intentional absence of any object value. This is one of the basic JavaScript values.

This is not completely absent, i.e. intentional absence, which means that someone wants to get a zero value in the position and use / update it later.

null have a unique meaning

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/null

+5

Layman, , -. null , , .

+2

null , ,

+1

Source: https://habr.com/ru/post/1676832/


All Articles