M
Matt Kruse
I recently came across this:
if (~str.indexOf('match')) {
// found it!
}
as opposed to:
if (str.indexOf('match')>-1) {
// found it!
}
I wasn't familiar with the bitwise NOT operator, having never used it
before or even considering it for testing cases that return -1 when
"not successful".
This syntax looks simple, though somewhat obfuscated because most
people would be unfamiliar with it.
Any thoughts?
Matt Kruse
if (~str.indexOf('match')) {
// found it!
}
as opposed to:
if (str.indexOf('match')>-1) {
// found it!
}
I wasn't familiar with the bitwise NOT operator, having never used it
before or even considering it for testing cases that return -1 when
"not successful".
This syntax looks simple, though somewhat obfuscated because most
people would be unfamiliar with it.
Any thoughts?
Matt Kruse