The code works perfectly ;-)
Just a minor remark. Using the "identity unequal" (!==) operator would avoid unneeded type conversions.