Back to articles
URL Encoding Explained: encodeURIComponent vs encodeURI (and When to Use Each)

URL Encoding Explained: encodeURIComponent vs encodeURI (and When to Use Each)

via Dev.to Tutorialze he

URL Encoding Explained: encodeURIComponent vs encodeURI URL encoding is one of those things that's easy to get wrong — and when you do, you get mysterious 400 Bad Request errors or mangled query strings. This guide covers everything you need to know. Quick tool: URL Encoder/Decoder — encode or decode URLs instantly in your browser. What Is URL Encoding? URLs can only contain a limited set of safe ASCII characters. Any other characters — spaces, Chinese characters, special symbols — must be "percent-encoded" using the format %XX where XX is the hex code of the character: Space → %20 & → %26 = → %3D # → %23 / → %2F So hello world becomes hello%20world in a URL. The Two JavaScript Functions encodeURIComponent() — For parameter values Encodes everything except: A-Z a-z 0-9 - _ . ! ~ * ' ( ) encodeURIComponent ( ' hello world ' ) // 'hello%20world' encodeURIComponent ( ' a & b = c ' ) // 'a%20%26%20b%20%3D%20c' encodeURIComponent ( ' https://example.com ' ) // 'https%3A%2F%2Fexample.com' en

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
2 views

Related Articles