This function returns an encoded string where all non-alphanumeric characters except – _ . are replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.
The escape function encodes all non-alphanumeric characters except * @ / + – _ .
The encodeURIComponent function encodes all non-alphanumeric characters except spaces and ! ‘ ( ) * ~
The winner for me though is encodeURIComponent as it encodes all UTF-8 characters while escape only encodes ISO Latin characters.
With this in hand, mozilla help provide a neat function.