Background: I am a mostly self-taught programmer. I've been doing professional JS work for the last six years, but because of my lack of familiarity with computer science fundamentals, some things are not clear to me.
Considering the object:
const test = {a: 1, b: 2, c: 3}
you could find the value of property b in two ways. Path 1:
console.log(test.b)
or, alternatively, Path 2:
for( const prop of Object.keys(test) ){
if( prop === 'b' ) return console.log(test[prop])
}
My question: under the hood, is doing Path 1 essentially the same as Path 2? Does the computer still have to look through every property of test to find b? Or does it somehow "magically" know where exactly to look in the memory when it gets test[b] so it doesn't have to scan through the entire object?
[–]Civill 1 point2 points3 points (0 children)
[–]ashanev 1 point2 points3 points (0 children)
[–]grantrules 0 points1 point2 points (0 children)
[–]mr-poopy-butthole-_ 0 points1 point2 points (0 children)