Tsallaka zuwa abun ciki
Justice Tech School

Comparing Values

Arrays and structs are comparable with ==. Slices and maps are not, use slices.Equal or reflect.

Example
package main

import (
	"fmt"
	"slices"
)

func main() {
	a := [3]int{1, 2, 3}
	b := [3]int{1, 2, 3}
	fmt.Println(a == b, slices.Equal([]int{1}, []int{1}))
}

Result

true true

Exercise

Compare slices.

slices.(a, b)

Quiz Test

Can you compare slices with ==?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.