Wednesday, 6 December 2017

JavaScript | What is undefined x 1 in JavaScript?

var names = ["John","Dev","Algos","Rob","Murphy"];
delete names[3];
When you run the code above and type console.log(names); into your Chrome developer console, you will get ["John","Dev","Algos", "undefined × 1", "Murphy"].

However, when you run the code in Firefox's browser console, you will get ["John", "Dev", "Algos", "undefined", "Murphy"].

Thus, it's clear that the Chrome browser has its own way of displaying uninitialized indexes in arrays. However, when you check names[3] === undefined in both browsers, you will get similar output as true.

Note: Please remember you do not need to check for the uninitialized index of an array of names[3] === 'undefined × 1', as it will give you an error. 'undefined × 1' is just way of displaying an array's uninitialized index in Chrome.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...