Created
January 15, 2016 17:13
-
-
Save tevko/ae37ea80387fe005cb2f to your computer and use it in GitHub Desktop.
Bitwise Operator and indexOf on strings
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
// "Bitwise operators perform their operations on such binary representations, but they return standard JavaScript numerical values." | |
//It transforms -1 into 0, and 0 is false in javascript, so: | |
var someText = 'text'; | |
!!~someText.indexOf('tex'); //sometext contains text - true | |
!~someText.indexOf('tex'); //sometext not contains text - false | |
~someText.indexOf('asd'); //sometext contains asd - false | |
~someText.indexOf('ext'); //sometext contains ext - true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment