Standard library / html/template

html/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"  "html/template")
func main() { fmt.Println(template.JSEscaper(`a"b`)) }
Go Reference