0

After looking at Sizzle.js I noticed they have an assert function (see below) which returns !!fn(x).

Why would anyone do that? It seems pointless to do that as it would just be "not not".

function assert( fn ) {
  var div = document.createElement("div");

  try {
    return !!fn( div );
  } catch (e) {
    return false;
  } finally {
    // release memory in IE
    div = null;
  }
}

Anyone shed any light on this?

Alexander
  • 22,498
  • 10
  • 56
  • 73
DarkMantis
  • 1,468
  • 4
  • 19
  • 39
  • 1
    AFAIK it is a way to "cast" to boolean, but maybe someone with more insight to this can elaborate more.. – pdu Feb 26 '13 at 12:12
  • Sorry I did have a look for another question simular but couldn't find it, it probably is a duplicate of the other question. – DarkMantis Feb 26 '13 at 12:21

1 Answers1

3

It makes sure the return type is boolean and nothing else.

Alexander
  • 22,498
  • 10
  • 56
  • 73
Emil Vikström
  • 84,510
  • 15
  • 132
  • 168