Both sides commit the turn’s commands before seeing the other choice. Higher Speed does not let you watch and revise.
For an attack, check whether it affects the target, its damage and a possible response. For a switch, check whether the replacement takes the incoming hit and what it can do next.
Ordinary attacks generally hit the replacement after a switch. Resistance or immunity only covers applicable attacks; low HP, other moves and entry effects can still make entry costly.
Against Flying, ungrounded
Corviknight with no immunity-changing effect,
Garchomp’s Earthquake fails while Dragon Claw is resisted but can damage. That removes one mistaken reason, not every alternative. Compare a real switch before declaring staying in best or promising a knockout.