w3schools says the following about
This function encodes special characters. In addition,
it encodes the following characters:.
, / ? : @ & = + $ #
This function encodes special characters. In addition, it encodes the following characters:
, / ? : @ & = + $ # .
This definition is vague as to what "special characters" are. It sounds like a comparison between
encodeURIComponent. Both will correctly escape
%5C, so you don't have to worry about backslashes.
encodeURI will leave the listed characters as it is assumed that the entire URI is being encoded:
encodeURI('http://example.com/foo bar/baz.html'); //produces "http://example.com/foo%20bar/baz.html"
encodeURIComponent will escape everything as it is assumed that the string is to be used as part of a query-string:
'http://example.com?foo=' + encodeURIComponent('http://example.com/fizz/buzz.html'); //produces "http://example.com?foo=http%3A%2F%2Fexample.com%2Ffizz%2Fbuzz.html"