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
| Name | Type | Description |
|---|---|---|
| w | io.Writer | Destination writer. |
| b | []byte | Bytes to escape. |
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "text/template")
func main() { template.JSEscape(os.Stdout, []byte(`a"b`)); fmt.Println() }