Doubt about double exclamation (!!) in javascript / Jquery

Asked

Viewed 3,054 times

7

I saw its use in the source code of Jquery, for example:

fired: function() {
    return !!fired;
}

Code snippet located between lines 3222 and 3224 of version 2.1.4 Uncompressed.


  • She’s something native to Javascript or created between the functionalities of the Jquery?

  • Can be found in other languages, if yes for example?

OBS.: I would like an example of the use in the answer.

Recast question after discussion meta.

  • 1

    -1 This question has already been asked

  • Discussion on the goal: http://meta.pt.stackoverflow.com/questions/4455/questions-duplicates-votos-positivos-pode-isso

  • @Dorivalzanetto this can happen, there is no problem. As long as you do not start to open duplicates in series. Everyone has made a duplicate once in their life.

  • This question is being discussed at the finish line: Duplicates shall be negative?

  • Just a note for those arriving now, the use of double exclamation can be replaced by the use of Boolean: Boolean(myVar) instead of !!myVar

1 answer

8

That doesn’t belong to jQuery, that’s Javascript. When you deny something twice, you are checking if a value is the inverse of false, try typing on your console: ! 'Hello World', and hit "enter", then try this: !! 'Hello World'; then try this: !![]+!![]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.