Context : I am trying to optimize my code for a reactjs project that I am working on using expo. In one of my if else statements, one boolean variable's value is changed based on whether any of multiple other boolean variables are false. I wanted to make this much more optimized and remove unnecessary code since its for a mobile app.
My question is : Is there a way to make an if statement shorter while checking whether a variable is false?
if(variable){}
is the same as
if(variable === true){}
Is there a way like this for false as well? Maybe something like
if(!variable){}
I'm not exactly sure and couldn't find any method similar to what I showed above anywhere online (yet).
Example of the code I have right now :
var example = false
if(var1 === false || var2 === false || var3 === false || var4 == false){
example = true
}
if any of the variables are false (hence the ||), it should switch over
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire