Is there a better way of checking if a gameObject has a component?

Am doing this:

if (previousObject.GetComponent() != null)
correctPos = previousObject.GetComponent();

But am getting the component twice. Is there a way to just check and have? Maybe is not that bad if I do this in awake or start, but it would be useful to know.

Collider component = previousObject.GetComponent();
if (component != null)
correctPos = component;
[EDITED] Removed incorrect part of the answer mentionning the “??” operator. see @Hellium comment below.

Answer is not 100% correct. Unamrked until its modifyed.