encodeURI() Used to encode a URI by replacing URL reserved characters with their UTF-8 encoding.
To know more, talk2us@ideas2it.com or visit www.ideas2it.com
2. encodeURI()
Used to encode a URI by replacing URL
reserved characters with their UTF-8 encoding.
const url = 'https://jsnuggets.com?todays #post';
encodeURI(url);
// "https://jsnuggets.com?todays%20#post"
decodeURI()
Used to decode the URI encoded by
encodeURI().
const url = 'https://jsnuggets.com?todays%20#post';
decodeURI(url);
// 'https://jsnuggets.com?todays #post';
3. encodeURIComponent()
encodeURIComponent is designed to encode
everything, where encodeURI ignores a URL's
domain related roots. In addition, it encodes
the following characters as well: , / ? : @ & =
+ $ #
const url = 'https://jsnuggets.com?todays #post';
encodeURIComponent(url);
// https%3A%2F%2Fjsnuggets.com%3Ftodays%20%23post
decodeURIComponent()
To decode the URI encoded by
encodeURIComponent().
const url =
'https%3A%2F%2Fjsnuggets.com%3Ftodays%20%23post';
decodeURIComponent(url);
// https://jsnuggets.com?todays #post
4. Works effectively on browser console too!!
const emoji = encodeURI('😉');
// %F0%9F%98%89
decodeURI(emoji);
// 😉