[Golang] undefined Test in GopherJS


Check if something (object, variable, API, ...) is undefined or not in GopherJS. Use js.Undefined in your if test.

For example, you can check if your browser supports localStorage API or not by:

package main

import (
        "fmt"

        "github.com/gopherjs/gopherjs/js"
)

func main() {
        if js.Global.Get("localStorage") == js.Undefined {
                fmt.Println("Your browser does not support localStorage API")
        } else {
                fmt.Println("Your browser supports localStorage API")
        }
}

Run Code on GopherJS Playground

For null test (if a variable is null), see [3].


References:

[1]GopherJS - A compiler from Go to JavaScript (GitHub, GopherJS Playground, godoc)
[2]Search undefined Results in GopherJS repo · GitHub
[3][GopherJS] null Test