Introduction
Encoding and decoding URLs helps make sure web addresses work correctly by handling special characters safely.
Jump into concepts and practice - no test required
encodeURIComponent(string) decodeURIComponent(string)
const encoded = encodeURIComponent('Hello World!');
console.log(encoded);const decoded = decodeURIComponent('Hello%20World%21');
console.log(decoded);const url = `https://example.com/search?query=${encodeURIComponent('node.js & url')}`;
console.log(url);const searchTerm = 'coffee & cream'; const encodedTerm = encodeURIComponent(searchTerm); const url = `https://example.com/search?query=${encodedTerm}`; console.log('Encoded URL:', url); const receivedParam = 'coffee%20%26%20cream'; const decodedTerm = decodeURIComponent(receivedParam); console.log('Decoded term:', decodedTerm);
encodeURIComponent function do in Node.js?encodeURIComponentdecodeURIComponent is used to decode encoded parts of a URL.decodeURIComponent('https%3A%2F%2Fexample.com') correctly decodes the encoded string.const encoded = encodeURIComponent('Hello World!');
console.log(encoded);const url = 'https://example.com/search?query=Node.js'; const encodedUrl = encodeURIComponent(url); console.log(encodedUrl);
encodeURIComponent encodes all special characters, including ':' and '/', which breaks full URLs.encodeURI is designed to encode full URLs without breaking their structure.user@example.com. Which code snippet correctly encodes this parameter for use in a URL?encodeURIComponent to encode special characters like '@'.const param = encodeURIComponent('user@example.com'); correctly encodes '@' as '%40'.