Standard library / html/template

html/template.JSEscapeString()

Escapes characters for JavaScript string content; does not validate executable scripts. Expected stdout: 'a\\"b\n'.

Formal Syntax & Structure

go syntaxgo
func JSEscapeString(s string) string

Parameters & Attributes

NameTypeDescription
sstringString to escape.

Return Value

string

Escapes characters for JavaScript string content; does not validate executable scripts.

Working Example

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