Bird
0
0

How do you encode the string 'hello world' as a URL component in Node.js?

easy📝 Syntax Q3 of 15
Node.js - URL and Query String Handling
How do you encode the string 'hello world' as a URL component in Node.js?
Aescape('hello world')
BencodeURI('hello world')
CdecodeURIComponent('hello world')
DencodeURIComponent('hello world')
Step-by-Step Solution
Solution:
  1. Step 1: Identify encoding function

    encodeURIComponent() encodes spaces as %20, suitable for components.
  2. Step 2: Apply function to string

    encodeURIComponent('hello world') returns 'hello%20world'.
  3. Final Answer:

    encodeURIComponent('hello world') -> Option D
  4. Quick Check:

    encodeURIComponent encodes spaces as %20 [OK]
Quick Trick: Use encodeURIComponent for strings with spaces [OK]
Common Mistakes:
  • Using encodeURI which leaves spaces unencoded
  • Using decode functions instead of encode
  • Using deprecated escape() function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes