SiteMap  | About    

What is undefined x 1 in JavaScript?

Part of the ECMA standard , Javascript consoles will display objects as arrays when the objects are array-like. Such as: ["hello", "world"] for an object containing strings that are numerically indexed. JavaScript arrays are implemented differs from browser to browser, but they generally fall back to a sparse implementation - most likely the same one used for property access of regular objects. However, Google Chrome seems to choose to display sparse array using this undefined x n notation. Here is how it looks, Type this code into Chrome developer console :


Above output show, the first two consecutive "undefined" that are represented by *2, to show that there are two consecutive undefined there. Although, if there is only one undefined value, they could drop the x 1. Thus, it's clear that the Chrome browser has its own way of displaying uninitialized indexes in arrays.

JavaScript Sparse Arrays

A sparse array is one in which the elements do not have contiguous indexes starting at 0. Normally, the length property of an array specifies the number of elements in the array. If the array is sparse, the value of the length property is greater than the number of elements. When array is sufficiently sparse (missing lots indexes), it loses its special efficiency when accessing array by indexes. In performance , it effectively is like a hashtable. (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.