Escape a string for use in JavaScript code
- Select JavaScript as the target context.
- Paste the raw string (e.g. content from a user input or file).
- Copy the escaped output and use it inside a string literal in your code.
Escape and unescape strings for different contexts like JS, HTML, JSON, and regex.
The String Escaper is an essential tool for developers working with strings in different contexts. It escapes and unescapes special characters for JavaScript, HTML, JSON, Regex, and URL encoding. Perfect for preventing syntax errors, security vulnerabilities, and ensuring proper string handling.
Testing escaped patterns afterward? Open our Regex Tester to validate regex behavior with real-time match highlighting and replacement output.
Common flow: escape input here, validate matches in regex pattern tester, normalize payloads in JSON Formatter, and verify schema using JSON Validator.
FAQ tip: when a question involves regex escaping edge cases, cross-check behavior in Regex Tester.
Step-by-step chains that connect related tools for common tasks.
Advertisement
In JavaScript strings, backslash (\), single quote ('), double quote ("), backtick (`), newline (\n), carriage return (\r), and tab (\t) must be escaped. Template literals also need backticks escaped. The escaper handles all of these, producing a safe string literal you can paste directly into code.
String escaping converts characters that would break code syntax — e.g. a quote inside a quoted string. URL encoding (percent-encoding) converts characters that are not safe in a URL context — e.g. spaces become %20. Use this tool for JS/HTML/JSON/regex context; use the URL Encoder for URL parameters.
Select the target context (JavaScript, HTML, JSON, regex, or URL) from the selector — the tool applies the correct escaping rules for that context. For example, JSON escaping handles Unicode escapes differently from JavaScript.
Yes — completely free with no signup and no usage limits.
More free tools for the same workflow.
Free HTML entity encoder—convert &, <, >, and quotes to &, <, > and decode entities back. XSS-safe for templates. Runs locally in your browser; no upload.
Free URL encoder decoder for query values and full URLs—encodeURIComponent & encodeURI. Percent-encode or decode instantly in your browser; never uploaded.
Advertisement