SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    790
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    pls help me understand this construction....

    Code:
    var canPlayAudioFiles = !!(document.createElement('audio').canPlayType);
    this is from an HTML5 book, to test whether the browser supports <audio> tag....

    I don't understand the '!!' before the parens.... I have never seen this before.. is this jQuery or plain Javascript?
    (asking because this line occurs inside a typical jQuery
    Code:
    $(function() {
    thingie... )

    could this be done with a classic boolean function/method????

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Hi,

    The double bang(!!) forces a boolean value out of any statement. This is plain 'ol javascript.

    It will change 'falsy' values like nil / undefined into false.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •