Skip to main content
Question Protected by Salman Arshad
edited tags
Link
Salman Arshad
  • 273.5k
  • 85
  • 450
  • 540

What How does !!~ (not not tilde/bang bang tilde) preceding this arrayalter the result of a 'contains/included' Array method call do?

If you read the comments at the jQuery inArrayinArray page here, there's an interesting declaration:

!!~jQuery.inArray(elm, arr) 

Now, I believe a double-exclamation point will convert the result to type booleanboolean, with the value of truetrue. What I don't understand is what is the use of the tilde (~) operator in all of this?

var arr = ["one", "two", "three"];
if (jQuery.inArray("one", arr) > -1)
  { alert("Found"); }

Refactoring the ifif statement:

if (!!~jQuery.inArray("one", arr))
  { alert("Found"); }

Breakdown:

jQuery.inArray("one", arr)     // 0
~jQuery.inArray("one", arr)    // -1 (why?)
!~jQuery.inArray("one", arr)   // false
!!~jQuery.inArray("one", arr)  // true

I also noticed that if I put the tilde in front, the result is -2.

~!!~jQuery.inArray("one", arr) // -2

I don't understand the purpose of the tilde here. Can someone please explain it or point me towards a resource?

What does !!~ (not not tilde) preceding this array method call do?

If you read the comments at the jQuery inArray page here, there's an interesting declaration:

!!~jQuery.inArray(elm, arr) 

Now, I believe a double-exclamation point will convert the result to type boolean, with the value of true. What I don't understand is what is the use of the tilde (~) operator in all of this?

var arr = ["one", "two", "three"];
if (jQuery.inArray("one", arr) > -1)
   alert("Found");

Refactoring the if statement:

if (!!~jQuery.inArray("one", arr))
   alert("Found");

Breakdown:

jQuery.inArray("one", arr)     // 0
~jQuery.inArray("one", arr)    // -1 (why?)
!~jQuery.inArray("one", arr)   // false
!!~jQuery.inArray("one", arr)  // true

I also noticed if I put the tilde in front, the result is -2.

~!!~jQuery.inArray("one", arr) // -2

I don't understand the purpose of the tilde here. Can someone please explain it or point me towards a resource?

How does !!~ (not not tilde/bang bang tilde) alter the result of a 'contains/included' Array method call?

If you read the comments at the jQuery inArray page here, there's an interesting declaration:

!!~jQuery.inArray(elm, arr) 

Now, I believe a double-exclamation point will convert the result to type boolean, with the value of true. What I don't understand is what is the use of the tilde (~) operator in all of this?

var arr = ["one", "two", "three"];
if (jQuery.inArray("one", arr) > -1) { alert("Found"); }

Refactoring the if statement:

if (!!~jQuery.inArray("one", arr)) { alert("Found"); }

Breakdown:

jQuery.inArray("one", arr)     // 0
~jQuery.inArray("one", arr)    // -1 (why?)
!~jQuery.inArray("one", arr)   // false
!!~jQuery.inArray("one", arr)  // true

I also noticed that if I put the tilde in front, the result is -2.

~!!~jQuery.inArray("one", arr) // -2

I don't understand the purpose of the tilde here. Can someone please explain it or point me towards a resource?

edited title
Link
Salman Arshad
  • 273.5k
  • 85
  • 450
  • 540

What does !!~ (doublenot not and tilde) preceding this array method call do?

Post Merged (destination) from stackoverflow.com/questions/10582286/…
edited title
Link
Bergi
  • 670.4k
  • 162
  • 1k
  • 1.5k
Loading
deleted 19 characters in body; edited tags; edited title
Source Link
Dennis
  • 14.5k
  • 3
  • 51
  • 58
Loading
Source Link
user717236
  • 5k
  • 20
  • 68
  • 102
Loading