Skip to content

Instantly share code, notes, and snippets.

@Jagathishrex
Created January 3, 2021 14:51
Show Gist options
  • Save Jagathishrex/88e13b110d54b0c3be46d27f0d09aefe to your computer and use it in GitHub Desktop.
Save Jagathishrex/88e13b110d54b0c3be46d27f0d09aefe to your computer and use it in GitHub Desktop.
let num = new Array(3); // creating an empty array with length 3
console.log(num); // [empty × 3]
console.log(num[0]); // undefined
// the callback function passed to Array.some method will not check the callback for unassigned values
num.some(a => {console.log(a); return a === undefined }) // false
// But Array.findIndex will check the callback function for unassigned values also
num.findIndex(a => {console.log(a); return a === undefined }) // undefined will be printed - 0 will be returned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment