Standard library / html/template
html/template.JS
Trusted JavaScript expression; can bypass escaping, so do not wrap untrusted input. Expected stdout: '<script>let n=1+2;</script>\n'.
Formal Syntax & Structure
go syntaxgo
type JS stringWorking Example
Example Snippetgo
package main
import ( "fmt" "html/template" "os")
func check(e error) { if e != nil { panic(e) }}
func main() { t := template.Must(template.New("x").Parse("<script>let n={{.}};</script>")) check(t.Execute(os.Stdout, template.JS("1+2"))) fmt.Println()}