Different code but still acceptable?

With the code that Sam writes at 5:10 is my version of it still acceptable? It appears to get the same results in play

My code:

if(GetUnlockableActor() != nullptr)
    {
        UE_LOG(LogTemp, Display, TEXT("Unlocking"));
    }
    else
    {
        UE_LOG(LogTemp, Display, TEXT("Relocking"));
    }

That is the same thing without the variable. The compiler would most likely optimise away the variable in the course so both code should be the same in the end.