Learn Tinygo-wasm - 10 Code Examples & CST Typing Practice Test
TinyGo WebAssembly (tinygo-wasm) is a lightweight Go compiler designed to build extremely small and fast WebAssembly binaries, enabling Go developers to run applications in browsers, edge devices, IoT systems, and embedded environments with minimal resource usage.
Learn TINYGO-WASM with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple TinyGo WASM Program
# tinygo/demo/main.go
package main
import (
"syscall/js"
)
func main() {
doc := js.Global().Get("document")
doc.Call("write", "Hello, TinyGo!")
select{}
}
A basic TinyGo program compiled to WebAssembly that prints 'Hello, TinyGo!' when executed.
TinyGo WASM Counter
# tinygo/demo/counter.go
package main
import (
"syscall/js"
)
var count int
func increment(this js.Value, args []js.Value) interface{} {
count++
doc := js.Global().Get("document")
doc.Call("write", count)
return nil
}
func main() {
doc := js.Global().Get("document")
doc.Call("write", "Counter: ")
js.Global().Set("increment", js.FuncOf(increment))
select{}
}
A simple counter using TinyGo and WebAssembly.
TinyGo WASM Button Click
# tinygo/demo/button.go
package main
import (
"syscall/js"
)
func click(this js.Value, args []js.Value) interface{} {
doc := js.Global().Get("document")
doc.Call("write", "Button clicked!")
return nil
}
func main() {
js.Global().Set("clickButton", js.FuncOf(click))
select{}
}
Prints a message when a JavaScript button is clicked.
TinyGo WASM Hello with Input
# tinygo/demo/input.go
package main
import (
"syscall/js"
)
func greet(this js.Value, args []js.Value) interface{} {
name := args[0].String()
doc := js.Global().Get("document")
doc.Call("write", "Hello, "+name+"!")
return nil
}
func main() {
js.Global().Set("greet", js.FuncOf(greet))
select{}
}
Reads input value and prints a greeting.
TinyGo WASM Even Check
# tinygo/demo/even.go
package main
import (
"syscall/js"
)
func isEven(this js.Value, args []js.Value) interface{} {
n := args[0].Int()
result := "Odd"
if n%2 == 0 {
result = "Even"
}
doc := js.Global().Get("document")
doc.Call("write", result)
return nil
}
func main() {
js.Global().Set("isEven", js.FuncOf(isEven))
select{}
}
Checks if a number is even and prints the result.
TinyGo WASM Fibonacci
# tinygo/demo/fibonacci.go
package main
import (
"syscall/js"
)
func fib(n int) int {
if n <= 1 {
return n
}
return fib(n-1) + fib(n-2)
}
func fibonacci(this js.Value, args []js.Value) interface{} {
n := args[0].Int()
result := fib(n)
doc := js.Global().Get("document")
doc.Call("write", result)
return nil
}
func main() {
js.Global().Set("fibonacci", js.FuncOf(fibonacci))
select{}
}
Calculates Fibonacci number and prints it.
TinyGo WASM Toggle Text
# tinygo/demo/toggle.go
package main
import (
"syscall/js"
)
var on bool
func toggle(this js.Value, args []js.Value) interface{} {
on = !on
text := "OFF"
if on {
text = "ON"
}
doc := js.Global().Get("document")
doc.Call("write", text)
return nil
}
func main() {
js.Global().Set("toggle", js.FuncOf(toggle))
select{}
}
Toggles displayed text between 'ON' and 'OFF'.
TinyGo WASM Add Numbers
# tinygo/demo/add_numbers.go
package main
import (
"syscall/js"
)
func add(this js.Value, args []js.Value) interface{} {
a := args[0].Int()
b := args[1].Int()
doc := js.Global().Get("document")
doc.Call("write", a+b)
return nil
}
func main() {
js.Global().Set("add", js.FuncOf(add))
select{}
}
Adds two numbers passed from JavaScript and prints the sum.
TinyGo WASM Log Message
# tinygo/demo/log.go
package main
import (
"syscall/js"
"fmt"
)
func logMessage(this js.Value, args []js.Value) interface{} {
fmt.Println("Hello from TinyGo WASM!")
return nil
}
func main() {
js.Global().Set("logMessage", js.FuncOf(logMessage))
select{}
}
Logs a message to the console from WASM.
TinyGo WASM Multiply Numbers
# tinygo/demo/multiply.go
package main
import (
"syscall/js"
)
func multiply(this js.Value, args []js.Value) interface{} {
a := args[0].Int()
b := args[1].Int()
doc := js.Global().Get("document")
doc.Call("write", a*b)
return nil
}
func main() {
js.Global().Set("multiply", js.FuncOf(multiply))
select{}
}
Multiplies two numbers passed from JavaScript and prints the result.
Frequently Asked Questions about Tinygo-wasm
What is Tinygo-wasm?
TinyGo WebAssembly (tinygo-wasm) is a lightweight Go compiler designed to build extremely small and fast WebAssembly binaries, enabling Go developers to run applications in browsers, edge devices, IoT systems, and embedded environments with minimal resource usage.
What are the primary use cases for Tinygo-wasm?
Running Go code in the browser via WebAssembly. IoT and microcontroller applications. Edge computing Wasm modules. WASI applications in runtimes like wasmtime or wasmer. Plugins for serverless Wasm platforms (Spin, Fermyon, WasmCloud, etc.)
What are the strengths of Tinygo-wasm?
Extremely small and fast WebAssembly output. Go syntax and tooling remain familiar. Perfect for IoT, edge, and low-power systems. Browser-compatible Wasm without huge runtime. Ideal for plugin systems in Wasm-based platforms
What are the limitations of Tinygo-wasm?
Not all Go standard library packages are supported. Garbage collector is simpler than in full Go. Some reflection features are limited. Multithreading (Go 1.22+) only partially supported. Debugging can be more difficult due to compiler optimizations
How can I practice Tinygo-wasm typing speed?
CodeSpeedTest offers 10+ real Tinygo-wasm code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.