Standard library / text/template
text/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) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | String to escape. |
Return Value
string
Escapes characters for JavaScript string content; does not validate executable scripts.
Working Example
Example Snippetgo
package main
import ( "fmt" "text/template")
func main() { fmt.Println(template.JSEscapeString(`a"b`)) }