Standard library / text/template

text/template.JSEscaper()

Formats arguments and escapes JavaScript string content. Expected stdout: 'a\\"b\n'.

Formal Syntax & Structure

go syntaxgo
func JSEscaper(args ...any) string

Parameters & Attributes

NameTypeDescription
args...anyValues formatted before escaping.

Return Value

string

Formats arguments and escapes JavaScript string content.

Working Example

Example Snippetgo
package main
import (  "fmt"  "text/template")
func main() { fmt.Println(template.JSEscaper(`a"b`)) }
Go Reference