5
  • Context: HTML web page (jade/node.js/javascript)
  • image url has strings with spaces/non-ascii characters
  • I need to encode these strings either with escape or urlencode.
  • as of now I am using escape to encode spaces specifically.

But I am not able justify/understand whether I should use escape to encode strings or should I use encodeurlcomponent. I tried reading some online blogs but not understood yet.

Any pointers to which one should be used under what circumstances.

0

1 Answer 1

7
  • escape() will not encode: @*/+

  • encodeURI() will not encode: ~!@#$&*()=:/,;?+'

  • encodeURIComponent() will not encode: ~!*()'

For more information, have a look at these questions:

Encode URL in JavaScript?

When are you supposed to use escape instead of encodeURI / encodeURIComponent?

Sign up to request clarification or add additional context in comments.

2 Comments

+1, though worth noting that escape is not a normative part of ES5, whereas the various encode/decodeURI functions are.
@RobG That's the first thing said in the answer on the 2nd link ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.