Don’t try to be too sneaky, especially when it needlessly affects performance.
If you really have a whole heap of comparisons to do, just format it nicely.
if (foobar === foo ||
foobar === bar ||
foobar === baz ||
foobar === pew) {
//do something
}
Related Contents:
- Sort array of objects by string property value
- Object comparison in JavaScript [duplicate]
- Sorting in JavaScript: Shouldn’t returning a boolean be enough for a comparison function?
- Is there a standard function to check for null, undefined, or blank variables in JavaScript?
- Comparing date part only without comparing time in JavaScript
- Switch statement for greater-than/less-than
- How do I check for null values in JavaScript?
- Why is string “11” less than string “3”? [duplicate]
- Why `null >= 0 && null
- Comparing Arrays of Objects in JavaScript
- Optimum way to compare strings in JavaScript? [duplicate]
- (…()) vs. (…)() in javascript closures [duplicate]
- JavaScript: Simple way to check if variable is equal to one of two or more values? [duplicate]
- Is it safe to assume strict comparison in a JavaScript switch statement?
- javascript surprising array comparison
- How to check identical array in most efficient way? [duplicate]
- Deep comparison of objects/arrays [duplicate]
- JavaScript performance difference between double equals (==) and triple equals (===)
- Javascript – deepEqual Comparison
- How to check if a variable is not null?
- Compare Strings Javascript Return %of Likely
- Wildcard string comparison in Javascript
- Convert dd-mm-yyyy string to date
- Parse an HTML string with JS
- Changing website favicon dynamically
- jQuery how to bind onclick event to dynamically added HTML element [duplicate]
- Is right click a Javascript event?
- SyntaxError: Use of const in strict mode
- Javascript RegExp + Word boundaries + unicode characters
- How to use underscore.js as a template engine?
- How to perform an integer division, and separately get the remainder, in JavaScript?
- How to set a Javascript object values dynamically?
- Problems with circular dependency and OOP in AngularJS
- Resetting a setTimeout
- How to get the exact local time of client?
- Export to csv in jQuery
- javascript user selection highlighting
- How to get data out of a Node.js http get request
- window.focus(), self.focus() not working in firefox
- Clearing my form inputs after submission
- What does this statement do? console.log.bind(console)
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- Playing sound in React.js
- What are some methods to debug Javascript inside of a UIWebView?
- How to update and delete a cookie?
- Count animation from number A to B
- Global variables in Meteor
- Force page scroll position to top at page refresh in HTML
- Calling onclick on a radiobutton list using javascript
- Client/JS Framework for “Unsaved Data” Protection?