-2

when i put one '=' instead of two or three equal character between two elements,the program goes wrong and it doesn't work properly i'd like to know why i can't make two element of different types equal to each other by one equal sign(=) but i can do with three or two but they aren't same type look at my code:

const progress=document.getElementById('progress')
const prev=document.getElementById('prev')
const next=document.getElementById('next')
const circles=document.querySelectorAll('.circle')

let currentActive=1

next.addEventListener('click',()=>{
    currentActive++
  
    if(currentActive>circles.length){
        currentActive=circles.length
    }
    update()
})

prev.addEventListener('click',()=>{
    currentActive--
    if(currentActive<1){
        currentActive=1

    }
    update ()


})

function update(){
circles.forEach((circle,idx)=> {
    
    if(idx<currentActive){
        circle.classList.add('active')
    }else{
        circle.classList.remove('active')
    }
    
})

    const actives=document.querySelectorAll('.active')
    progress.style.width=(actives.length - 1) / (circles.length - 1) * 100 + '%'
    
    if(currentActive=== 1){
        prev.disabled=true
    }else if(currentActive === circles.length){
        next.disabled=true

    }else{
        prev.disabled=false
        next.disabled=false
    }
}

current active is a variable which contains number and circles.length is an element which contains number. although they aren't same type,when i put three equals,program runs correctly but when i put one equal it doesn't. it should be opposite because they can't be same type.

Progman
  • 16,827
  • 6
  • 33
  • 48
  • 2
    A single `=` is an assignment, two `==` are a comparison. Two completely different things. Therefore your question is very confusing – UnholySheep Apr 27 '22 at 19:13
  • 2
    I think you're confusing `=` (assignment), `==` (loose equality), and `===` (strict equality). – kelsny Apr 27 '22 at 19:13
  • If you're using `=` for assignment, how do you not see the necessity for a different operator to perform equality testing? Assignment and equality tests are allowed in overlapping contexts, they need different operators. – ShadowRanger Apr 27 '22 at 19:15

1 Answers1

0

= is an assignment operator, it will assign right hand value to left hand variable, on the other side == or === are comparison operator which checks whether LHS is equal to RHS or not. So if you are comparing the values, use == or ===.

Note: == -> It just checks the value. === -> It checks object type and value