I am trying to execute the function doSomething() ONLY if a global variable is TRUE. However, doSomething() still runs even when isTrue is FALSE. How come?
function doSomething() {
console.log("DOING SOMETHING")
}
var isTrue = false
function doOrNotDo() {
if (isTrue = true) {
doSomething()
}
else {
console.log("YO")
}
}
doOrNotDo()
Even if I comment out the variable declaration isTrue, the code still runs doSomething ,for some weird reason I have yet to understand.
Please advice, thanks!
Aucun commentaire:
Enregistrer un commentaire