jsonecho

Escapar JavaScript

Prepara texto para insertarlo de forma segura en una cadena JavaScript.

Cargando la herramienta...

Cómo usar Escapar JavaScript

  1. Pega el texto.
  2. Copia el resultado escapado.

Sobre Escapar JavaScript

Cuando construyes una cadena en JavaScript, necesitas escapar comillas, barras invertidas y algunos caracteres de control. Esta herramienta lo hace por ti.

What gets escaped

Backslash becomes \\, quotes become \" and \', a line break becomes \n, a tab \t, other control characters \xNN.

Preguntas frecuentes

Does it work for template literals?

Partly. The result is valid inside them, but backticks and ${ are not escaped. If your text contains those, escape them by hand.

Why is the forward slash option there?

Escaping / as \/ prevents a closing script tag inside a string from ending an HTML script block early. It is only needed if you put the JavaScript inside HTML.

What are U+2028 and U+2029?

Line and paragraph separators. Before ES2019 they were illegal in string literals, so this tool always escapes them.

Should I escape non-ASCII characters?

Usually not, modern JavaScript files are UTF-8 and happily hold é or 日本語. Turn the option on only when the file travels through something that might mangle encodings.

Más en Escape y texto

Todas las herramientas →