Skip to content

Instantly share code, notes, and snippets.

@tevko
Created January 15, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tevko/ae37ea80387fe005cb2f to your computer and use it in GitHub Desktop.
Save tevko/ae37ea80387fe005cb2f to your computer and use it in GitHub Desktop.
Bitwise Operator and indexOf on strings
// "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