-1

i have this code and i dont know what does =+ means it does not work like += hence

x+=y adds y value to x but x=+ it looks like its replace x value with y value

var counters= document.querySelectorAll('.counter'); 
counters.forEach(counter => {

    counter.innerText= '0' ; 
    const updateCounter = ()=> {
        const target =+ counter.getAttribute('data-target')
        const c = +counter.innerText
        const increasment = target/200;
        if(c<target) {
            counter.innerText = c+increasment ; 
            setTimeout(updateCounter,5)
        }
        else {
            counter.innerText=target 
        }
     
     
        
    }

    updateCounter(); 
})
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74

1 Answers1

0

This is a separate operator from the assignment operator (=). It is a unary plus, which converts the operand to a number if it isn't one already. So it's basically just a short but not very readable way of saying

const c = Number(counter.innerText)
Jonas Høgh
  • 10,358
  • 1
  • 26
  • 46