Programming Tips - How do I encode a URL string that might contain forbidden characters

Date: 2013sep18 Language: javaScript Keywords: escape, decode, encode, URI, component, part Q. How do I encode a URL string that might contain forbidden characters like space or backslash? A. Modern browsers have these functions build in:
encodeURI() encodeURIComponent()
Example use:
const myfile = 'c:\\windows\\hello.txt'; const myurl = 'http://host.com/?file=' + encodeURIComponent(myfile);