Java and JavaScript (.js) source files can use any character encoding. If one programmer uses UTF-8 and the other ISO encoding, there is a chance you will end with something like "Ren�" or "René" instead of "René". The most reliable way to avoid all conversion errors is to encode all special characters with escape sequences. JavaScript allows both hex (e.g. \xFF
) and Unicode escape sequences (e.g. \u0100
) in string literals while Java allows Unicode escape sequences only.
Click here to see it in action.
Tested with Opera, Firefox and Internet Explorer 8 (insufficient CSS support, but it works).
@maettig: You can lose one of the
+
after return if you just want to coerce to Number/NaN.