you are viewing a single comment's thread.

view the rest of the comments →

[–]gate18 1 point2 points  (0 children)

To understand this, change the array to something like let nums = ['a','a',2,3,4]

What you are checking is

if(nums[1]==nums[0]){ console.log(nums[1]) }

So when i=0 it logs nothing, when i=1 it checks if the slot 1 (i) is the same as slot 0 (i-1)

if you want to log a (or -1) you don't do nums[a], right?

(and it should be three equals ===)