Standard library / text/template

text/template.JSEscape()

Writes escaped JavaScript string content; not a general script sanitizer. Expected stdout: 'a\\"b\n'.

Formal Syntax & Structure

go syntaxgo
func JSEscape(w io.Writer, b []byte)

Parameters & Attributes

NameTypeDescription
wio.WriterDestination writer.
b[]byteBytes to escape.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "text/template")
func main() { template.JSEscape(os.Stdout, []byte(`a"b`)); fmt.Println() }
Go Reference