My teacher told me in order to undo $\log$ you have to base both sides with the same number of the existing $\log$, but I don’t really understand why 4 and the power which is $\log_4$ cancels each other out, someone please tell me the process of it, not just the formula which I already know.

You're basically asking simplification of $$a^{\log_a b} \tag 1$$
So suppose $$\log_b a =c$$
By definition of log, we've $$\log_b a =c \implies a^c =b \tag2$$
Now using $(2)$ and $(1)$, we get $$a^{\log_a b}=a^{(c)}\tag3 $$
Now using $(3)$ and $(2)$, finally we've $$a^{\log_a b} =b$$