The general idea would be to compute $ \lim_{x \to x_0} \frac{ f(x) - f(x_0) }{x - x_0}. $ Now it would help if we could save ourselves some time in particular cases. When the derivative of the function is just well-known by standard techniques, go for it. If your function is piece-wise defined, then you can look at the domain where the pieces are well-known differentiable functions. For instance $ |x| = \begin{cases} x & \text{ if } x > 0 \\ -x & \text{ if } x < 0 \\ 0 & \text{ if } x = 0. \end{cases} $ Note that I haven't included $0$ in either of the cases. Why? Because a single point can be treated alone, and the other constraints on the domain are open sets, that is, for every point in the set $\{ x > 0 \}$, when I get close enough to any point $x_0$ from that set, I am sure that I am still in that set. The same goes for $x < 0$. Although for $x = 0$ I don't have such luxury ; if I want to compute the derivative, I have to consider two "pieces" of my piece-wise defined function, which is not very nice to deal with.
Since $x$ and $-x$ are differentiable functions and that they coincide with $|x|$ over open intervals (here $x$ coincides with $|x|$ over $\{ x > 0 \}$ and $-x$ coincides with $|x|$ over $\{ x < 0\}$, everywhere there I can say that their derivatives are equal (i.e. $+1$ when $x > 0$ and $-1$ when $x < 0$). I cannot say the same for $x = 0$ because no differentiable function coincides with $|x|$ over an open interval containing $0$, since $|x|$ is not differentiable there.
Hope that helps,