No-Bullshit Guide to Detecting Everything in HTML5
diveintohtml5.org
No-Bullshit Guide to Detecting Everything in HTML5
1–10 of 37 posts
Re: No-Bullshit Guide to Detecting Everything in HTML5
#2Excuse my ignorance, what's the !! for?
Re: No-Bullshit Guide to Detecting Everything in HTML5
#3Excuse my ignorance, what's the !! for?
converts a value that evaluates to false, to an actual false boolean.
Re: No-Bullshit Guide to Detecting Everything in HTML5
#4Excuse my ignorance, what's the !! for?
Its two negation operators. The first returns false is the object exists and true if it doesn't and the second flips that around.
So you get true if the object exists and false otherwise.
Re: No-Bullshit Guide to Detecting Everything in HTML5
#5Excuse my ignorance, what's the !! for?
Double negation is used for explicit boolean conversion, i.e.:
!!0 -> false
!!1 -> true
!!"" -> false
!!"s" -> true
!!null -> false
!!undefined -> falseRe: No-Bullshit Guide to Detecting Everything in HTML5
#6Excuse my ignorance, what's the !! for?
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.Re: No-Bullshit Guide to Detecting Everything in HTML5
#7Excuse my ignorance, what's the !! for?
Canonicalization, so that e.g. null and undefined turn into false and ordinary values (e.g. functions, arrays, numbers, objects) turn into true.
Try putting things like these into the address bar of your browser:
javascript:alert(!!null)
javascript:alert(!!undefined)
javascript:alert(!!{})
javascript:alert(!!Math.floor)Re: No-Bullshit Guide to Detecting Everything in HTML5
#8Excuse my ignorance, what's the !! for?
Ahh, thanks for that. Coercion to boolean.
Re: No-Bullshit Guide to Detecting Everything in HTML5
#9I'm constantly confused by 'HTML5', because many of these examples look more like Javascript than a markup language. I've used HTML5 a bit here and there, but just as the next version of XHTML, using things like the tag.
Re: No-Bullshit Guide to Detecting Everything in HTML5
#10Useful. Sadly, I don't see detection for @font-face -- perhaps because it's not very simple?