Go Basics

Comparison Operators

Description

Used to compare two values. Returns a boolean `true` or `false`. `==`, `!=`, `>`, `<`, `>=`, `<=`.

Pros & Cons

✅ Pros

  • Safety: Cannot compare mismatched types (e.g. int vs float) without casting.

❌ Cons

  • None.

When to Use

Conditional logic.

Example

Comparing variables.

x := 5
y := 3
fmt.Println(x > y)  // true
fmt.Println(x == y) // false

Best Practices

Pointers compare equal if they point to the same address.

← Assignment OperatorsLogical Operators →