Challenge - 5 Problems
URL Encoding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of decoding a URL component?
Consider the following Node.js code snippet that decodes a URL component. What will be the output?
Node.js
const encoded = 'Hello%20World%21';
const decoded = decodeURIComponent(encoded);
console.log(decoded);Attempts:
2 left
💡 Hint
decodeURIComponent converts percent-encoded characters back to normal characters.
✗ Incorrect
The string 'Hello%20World%21' is percent-encoded. decodeURIComponent converts '%20' to space and '%21' to '!'.
❓ Predict Output
intermediate2:00remaining
What does encodeURI do with special characters?
What is the output of this Node.js code that uses encodeURI on a URL string?
Node.js
const url = 'https://example.com/a file.html?name=John Doe&age=30';
const encoded = encodeURI(url);
console.log(encoded);Attempts:
2 left
💡 Hint
encodeURI encodes spaces but leaves URL special characters like ':' and '?' intact.
✗ Incorrect
encodeURI encodes spaces as '%20' but does not encode characters like ':', '/', '?', '=', '&'.
📝 Syntax
advanced2:00remaining
Which option causes a SyntaxError when decoding a URL component?
Which of the following decodeURIComponent calls will cause a SyntaxError in Node.js?
Attempts:
2 left
💡 Hint
Invalid percent-encoding sequences cause SyntaxError in decodeURIComponent.
✗ Incorrect
Option A has an incomplete percent-encoded sequence '%E0%A4%A' which is invalid and causes SyntaxError.
❓ component_behavior
advanced2:00remaining
How does encodeURIComponent treat reserved URL characters?
Given the string 'name=John&age=30', what will encodeURIComponent produce?
Node.js
const input = 'name=John&age=30'; const output = encodeURIComponent(input); console.log(output);
Attempts:
2 left
💡 Hint
encodeURIComponent encodes all characters except letters, digits, and a few others.
✗ Incorrect
encodeURIComponent encodes '=' as '%3D' and '&' as '%26', so the entire string is encoded.
❓ state_output
expert2:00remaining
What is the final value of 'url' after encoding and decoding?
Consider this Node.js code. What is the final value of the variable 'url' after running all lines?
Node.js
let url = 'https://example.com/search?query=Node.js & encoding';
url = encodeURI(url);
url = decodeURIComponent(url);
Attempts:
2 left
💡 Hint
encodeURI encodes spaces as '%20' but leaves '&' intact; decodeURIComponent reverses encoding.
✗ Incorrect
encodeURI encodes spaces as '%20' but leaves '&' as is. decodeURIComponent converts '%20' back to space. So final string matches original.