Avatar ·

Difference between == and === in Go

Hello everyone! I'm learning Go after JavaScript and encountered confusion with comparison operators. In JS there is strict (===) and non-strict (==) comparison, but in Go I only see ==. Am I correct in understanding that Go does not have the === operator? And if it doesn't, how does comparison work for different types?

I tried writing this code:

package main\n\nimport "fmt"\n\nfunc main() {\n    var a int = 5\n    var b float64 = 5.0\n    fmt.Println(a == b) // Compilation error: mismatched types int and float64\n}

I expected that Go would either convert types (like non-strict comparison in JS) or throw an error. I got a compilation error. So in Go you can't directly compare int and float64 at all? Do you always need to explicitly convert?