Differences between encodeURI, encodeURIComponent, and escape: Unicode characters

JavaScript FAQ | Strings & RegExp FAQ | URL-encoding  

As a simple example of Unicode (non-ASCII) characters, the table below shows the URL encodings for part of the Cyrillic subset of the Unicode character set (\u0410 thru \u042F). Note that the same Unicode character may produce the encoding

%uXXXX
if you use
escape
and the encoding
%XX%XX
if you use
encodeURI
or
encodeURIComponent
.

Importantly, the functions

escape
,
encodeURI
, and
encodeURIComponent
work like that for other parts of the Unicode character set as well: only the
escape
function may return the encoding of the form
%uXXXX
. (See also ASCII and upper ASCII characters.)
chr    escape(chr)   encodeURI(chr)  encodeURIComponent(chr)

Note also that for many Unicode characters,

encodeURI
or
encodeURIComponent
return the encoding
%XX%XX%XX
rather than
%XX%XX
, for example:
chr    escape(chr)   encodeURI(chr)  encodeURIComponent(chr)
(See Mathematical and Special Symbols for more examples.)

Copyright © 1996-2018, JavascriptFAQ.net.