This is in regards to a debate I had with an interviewer when I was interviewing at Amazon.
Let's I create an object:
var Obj = {};
Obj['SomeProperty'] = function ( ) { console.log("Accessed some property"); };
Obj[69] = true;
Is there anything in the JavaScript guaranteeing that when I subsequently access those 2 properties like Obj['SomeProperty']
and Obj[69]
the respective values function ( ) { console.log("Accessed some property"); };
and 69
are looked up in O(1) time? I know the access operator []
gives a seasoned programmer the impression that he's dealing with an O(1) lookup structure, but can't it be possible for a JavaScript engine to implement Object
in a way such that properties are not looked up in O(1)?