DEV Community

Discussion on: Can You Guess the Result of This JavaScript Code?

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Here's another one: Can you figure out what this expression will return?

Array.prototype.findLastIndex.call({length: 20}, value => value==undefined)
Enter fullscreen mode Exit fullscreen mode

It should be obvious what it does at face value, but can you tell for sure if that actually works without running it? ;)

Collapse
 
jaivardhanbhati profile image
Jai Bhati

return the index of the first element where there is no value present (undefined) in reverse order like 19..18..17...

Collapse
 
jaivardhanbhati profile image
Jai Bhati

This is why its the last index but internally the traversal is done from the reverse order