Created
July 6, 2010 05:49
-
-
Save dgoodlad/465062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Apparently JS has a tilde (~) operator. It's a unary operator that returns -(N + 1). So, using it and indexOf seems to give you a simple but unreadable test for substring detection. Since indexOf('stringthatisntthere') returns -1, the ~ operator turns that into -(-1 + 1) = -0 = 0, which is false. Otherwise, it'll always be true. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ua = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.2 (KHTML, like Gecko) Chrome/6.0.453.1 Safari/534.2"; | |
~ua.indexOf("Firefox") // => false | |
~ua.indexOf("Chrome") // => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment