$$ x^2 - x - 2 = 0 $$
$$ (x-2)(x+1) = 0 $$
$$ x = -1, 2 $$
in the given example, (x-2)(x+1) where x is -2 and +1 why did the last line of the example was swap?
In the real numbers (and complex numbers, and integers, and rationals), if a product is equal to $0$, then at least one factor is equal to zero.
So for $(x-2)(x+1)$ to be equal to zero, either $x-2=0$, or $x+1=0$.
However, for $x-2$ to equal $0$ you don't need $x$ to be equal to $-2$, you need it to be equal to $2$: $x-2=0$ is equivalent to $x=2$. And for $x+1=0$ to be true, you need $x=-1$. So that's why you go from "$x$ minus $2$" to $x=2$, and from "$x$ plus $1$" to $x=-1$.
(In general, $x$ equals $a$ if and only if $x-a=0$. And $x+1 = x-(-1)$).