0
0
Node.jsframework~5 mins

Encoding and decoding URLs in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is URL encoding and why is it important?
URL encoding converts characters into a format that can be transmitted over the internet. It replaces unsafe ASCII characters with a '%' followed by two hexadecimal digits. This ensures URLs are valid and data is correctly interpreted.
Click to reveal answer
beginner
Which Node.js global functions are used to encode and decode URLs?
encodeURIComponent() is used to encode a URI component by escaping characters. decodeURIComponent() reverses this process, decoding the encoded URI component back to its original form.
Click to reveal answer
intermediate
What is the difference between encodeURI() and encodeURIComponent() in Node.js?
encodeURI() encodes a full URI but leaves characters like '/', ':', and '?' intact. encodeURIComponent() encodes every character that is not a letter, number, or one of a few special characters, making it safer for encoding query parameters.
Click to reveal answer
beginner
How do you decode a URL string in Node.js?
Use decodeURIComponent() to convert an encoded URL component back to its original string. For example, decodeURIComponent('%20') returns a space character.
Click to reveal answer
beginner
Why should you encode query parameters in URLs?
Query parameters may contain special characters like spaces or '&' that can break the URL or cause errors. Encoding ensures these characters are safely transmitted and correctly interpreted by servers and browsers.
Click to reveal answer
Which function should you use to encode a query parameter in Node.js?
AdecodeURI()
BencodeURI()
CdecodeURIComponent()
DencodeURIComponent()
What does decodeURIComponent('%20') return?
AA space character
BThe string '%20'
CAn error
DA plus sign (+)
Which characters does encodeURI() NOT encode?
AAll special characters
BCharacters like '/', ':', and '?'
COnly letters and numbers
DSpaces only
Why is URL encoding necessary?
ATo make URLs safe for transmission by replacing unsafe characters
BTo shorten URLs
CTo encrypt URLs
DTo add colors to URLs
Which function reverses the encoding done by encodeURIComponent()?
AencodeURI()
BdecodeURI()
CdecodeURIComponent()
Descape()
Explain how and why you would encode and decode URLs in a Node.js application.
Think about sending data in URLs and how special characters affect them.
You got /4 concepts.
    Describe the difference between encodeURI() and encodeURIComponent() with examples.
    Consider when you want to encode a full link versus just a piece of it.
    You got /4 concepts.