News for hackers. Stuff that matters.
Re:No-Bullshit Guide to Detecting Everything in HTML5 by rlivsey on Friday May 14, 2010 @07:35AM (#1347094)
It makes sure that it returns a boolean value as opposed to something truthy/falsy which could lead to oddness if you try and directly compare it with a boolean value.

According to the spec, media.canPlayType returns either "", "maybe" or "probably". An empty string "" is falsy in Javascript and a non-empty string is truthy, but if you try and compare them directly with booleans then you can get some odd behaviour:

  if ("yes"){ // true }
  if ("yes" == true){ // false }
  if ("yes" === true){ // false }

  if (""){ // false }
  if ("" == false){ // true }
  if ("" === false){ // false }
I personally prefer to make sure that any function which you're expecting the return value to be used as a boolean actually returns a boolean value. I know there are many people out there with a dislike of !! though.

There are no comments on this comment yet.