How to Call JavaScript from Go Wasm

Web
Call JavaScript from Go WebAssembly using the syscall/js package to access global objects and invoke methods.

You call JavaScript from Go WebAssembly by using the syscall/js package to reference a global JavaScript object and invoke its methods.

package main

import (
	"syscall/js"
)

func main() {
	window := js.Global().Get("window")
	window.Call("alert", "Hello from Go!")
}

Compile your Go code with GOOS=js GOARCH=wasm go build -o main.wasm and load the resulting .wasm file in a browser using a Go runtime loader.