In some cases they could be used to get things that were in the game "legitimately" but which you might not have access to. E.g. getting Mew in Pokemon Blue/Red or Surfing Pikachu in Pokemon Yellow.
Sometimes the codes would break in interesting ways. For example, an invincibility code might cause problems if it was on during a battle that you are scripted to lose. Or the "invincibility" code might actually work by instantly healing you; so you might find out that you are vulnerable if an enemy is strong enough to take all of your health with a single hit.
Like the parent post said, there was a lot of experimentation even when everything was working "correctly".
In some cases they could be used to get things that were in the game "legitimately" but which you might not have access to. E.g. getting Mew in Pokemon Blue/Red or Surfing Pikachu in Pokemon Yellow.
Sometimes the codes would break in interesting ways. For example, an invincibility code might cause problems if it was on during a battle that you are scripted to lose. Or the "invincibility" code might actually work by instantly healing you; so you might find out that you are vulnerable if an enemy is strong enough to take all of your health with a single hit.
Like the parent post said, there was a lot of experimentation even when everything was working "correctly".