Miles Morales
Miles Morales

Reputation: 258

Kotlin: What is the difference between = vs ==?

I'm trying to set a certain value, monsterHealth, to display 0 instead of a negative number. If I'm trying to reassign the value to show 0 instead of, say, -2, would I want to use = or ==?

Upvotes: 1

Views: 79

Answers (1)

ulou
ulou

Reputation: 5853

Those are different operators:

  • = - assignment operator,
  • == and != - equality operators,
  • === and !== - referential equality operators.

also

  • val - read only variable/property (it cannot be reassigned/changed),
  • var - mutable variable/property.

Kotlin Documentation - Keywords and operators

Upvotes: 1

Related Questions