Reputation: 5572
I have an array. I would like do some operation based on the presence of items in the array.
Which approach is better in performance using javascript.
if (!myArr.length) {
//do something.
}
OR
if (myArr.length === 0) {
// do something
}
Upvotes: 0
Views: 24
Reputation: 1074178
Which approach is better in performance using javascript
The answer to this question for JavaScript code is almost always:
It depends on the engine, and
If it matters, test it on the engines you need to support. Here's a test you can use.
I very much doubt that it matters, though, this is unlikely to be a performance bottleneck in your code.
Upvotes: 2