Message from JavaScript discussions

September 2020

— Any React Native developer here?

— 

Language:

js


Source:
let a = [];

a[0] = '0';
a[2] = '2';

console.log(`
a[1]: ${a[1]}
a[1] == undefined: ${a[1] == undefined}
a[1] === undefined: ${a[1] === undefined}
1 in a: ${1 in a}
hasOwnProperty: ${Object.hasOwnProperty(a, 1)}
`)


Result:

a[1]: undefined
a[1] == undefined: true
a[1] === undefined: true
1 in a: false
hasOwnProperty: false

— Its undefined but in/hOP return false

— Anyone with React Native?

— Undefined is undefined man, it doesn't even tell if the array is (was) sparse, means that data structure was screwed even more🤧 i'm sure there is some use-case for non-solid-smartass arrays but that don't deserve enough memory to remember..

Message permanent page

— Nope!

— I see you use that awful php syntax🤔

— Nope is nope man!

— Language:

js


Source:
console.log(`${1 in [1, undefined, 2]}, ${1 in (()=>{let a = []; a[0] = 1; a[2] = 2; return a;})()}`)


Result:
true, false

Message permanent page

— You mean template literals?

— Ye, better functional style one-liner🤤 my point was about higher levels of purism, but making tiny tests is fine..

Message permanent page

— Should be

a = ...
b = ...
c = ...
console.log a, b, c