I have a little doubt. I tried to solve this limit in two different ways, one works and the other doesn't but I don't understand why. I would really appreciate if someone could help me to understand where did I make the mistake.
Fist way (that works) \begin{align*} \lim_{x \to 0} \frac{2x^2}{1 - \cos x} \cdot \frac{1 + \cos x}{1 + \cos x} & = \lim_{x \to 0} \frac{2x^2 (1 + \cos x)}{\sin^2 x} \\ & = \lim_{x \to 0} 2 \cdot \frac{x^2}{\sin^2 x} \cdot (1 + \cos x) \\ & = 2 \cdot 1 \cdot 2 \\ & = 4. \end{align*}
Second way (that doesn't work)
\begin{align*} \lim_{x \to 0} \frac{2 x^2}{1 - \cos x} \cdot \frac{1 + \cos x}{1 + \cos x} & = \lim_{x \to 0} \frac{2 x^2 (1 + \cos x)}{(1 - \cos x)(1 + \cos x)} \\ & = \frac{0}{0} \end{align*}
For your second way, you ended with where you started. Since you cancel away $(1+\cos x)$ after you introduce them.
If you substitute the value in and you encounter $\frac{0}{0}$, it is in indeterminate form and L'hopital's rule is a useful tool.
$$\lim_{x \to 0} \frac{2x^2}{1-\cos x}=\lim_{x \to 0} \frac{\frac{d}{dx}(2x^2)}{\frac{d}{dx}(1-\cos x)}=\lim_{x \to 0}\frac{4x}{\sin x}=4$$