Testing increasing index and decreasing but NaN

let index = 0;

const btnLeft = function(index){
     console.log('left', index--);
            
};
const btnRight = function(index){
    console.log('right', index++);
            
 };
          
left.addEventListener('click', btnLeft);
right.addEventListener('click', btnRight);

why I got NaN instead of 1,2,3 or 0,-1 :expressionless:

Hi @grzesiekmq,

Because you pass index as an argument to the method, that isn’t necessary, since it’s already available in context:

let index = 0;

const btnLeft = function(){
     console.log('left', index--);         
};
2 Likes

ok thanks