After plotting this function on desmos, I understood that this absolute expression is actually a piecewise function.
Hence this: $$f(x)=|x+1|+|x-1|$$is the same as
$$f(x)=\left\{\begin{align}2x\quad&\text{if }x>1\\-2x\quad &\text{if }x<-1\\2\quad &\text{if}-1<x<1\end{align}\right.$$
But is there a way to do this algebraically instead of plotting?
The way to see this is as follows: you must observe that $$|f(x)| = \begin{cases} f(x), & f(x) \geq 0 \\ -f(x), & f(x) < 0\text{.} \end{cases}$$ It does not matter where the equality sign goes (i.e., $\geq$ as opposed to $>$, or $<$ as opposed to $\leq$) in the vast majority of situations.
We thus have $$|x + 1| = \begin{cases} x + 1, & x + 1 \geq 0 \\ -(x+1), & x + 1 < 0 \end{cases} = \begin{cases} x + 1, & x \geq -1 \\ -x - 1, & x < -1 \end{cases}$$ $$|x - 1| = \begin{cases} x - 1, & x - 1 \geq 0 \\ -(x - 1), & x - 1 < 0 \end{cases} = \begin{cases} x - 1, & x \geq 1 \\ -x + 1, & x <1\text{.} \end{cases}$$ Next, we must add these functions together.
First, observe that $|x + 1|$ is defined piecewise over the intervals $(-\infty, -1)$ and then $[-1, \infty)$. These are indicated by the blue and red below respectively.
For $|x - 1|$, we must look at $(-\infty, 1)$ and then $[1, \infty)$. These are indicated by the orange and green below respectively.
Apologies for my art skills.
Given the above, it is clear that the sum of $|x + 1|$ and $|x- 1|$, as a piecewise function, must have three components:
The blue-orange component is when $x < -1$, or $|x + 1| = -x - 1$ and $|x - 1| = -x + 1$. Thus the sum of these is $-x - 1 + (-x + 1) = -2x$.
The red-orange component is when $-1 \leq x < 1$, or $|x + 1| = x + 1$ and $|x - 1| = -x + 1$. Thus the sum of these is $x + 1 + (-x + 1) = 2$.
The red-green component is when $x \geq 1$, or $|x + 1| = x + 1$ and $|x - 1| = x - 1$. Thus the sum of these is $x + 1 + (x - 1) = 2x$.