For example, instead of:
if (ext === "_st" || ext ==="_mt" || ext === "_00" ){
//do something
}
I would intuitively expect that the following also works:
if (ext === ("_st" || "_mt" || "_00" )){
//do something
}
But that doesn't work. Is there a way to avoid repeating the same ("ext" in this case) variable for more compressed and efficient code?
UPDATE: I did a search before asking and none of the "duplicate" questions appeared in the first 10-15 suggestions. Instead, StackOverflow made WRONG suggestions for irrelevant -false duplicates.
Here is my suggestion: Instead of marking questions as "duplicate" why not merge them along with the answers in one single question with an intuitive title?
Thanks for the answers.
UPDATE #2: This is NOT a duplicate. The suggested questions have answers that only refer to OR optimization while my question is more general, it refers to "logic expressions", NOT specifically to OR. I just provided an OR example. I'm specifically asking whether there is a method to avoid repeating the main variable in a logical statement whether it is OR, AND, etc.
For example: given var1
== var2
== var3
if (ext === var1 && ext === var2 && ext === var3 ){
//do something
}