 <p><code>\</code> denotes the start of an escape sequence, so it has to be escaped with another <code>\</code>.</p> <p>To replace globally, you need to use regex, which requires even more character escaping:</p> <pre><code> &gt; 'C:/TEST/'.replace(/\//g, '\\') "C:\TEST\" </code></pre>