How to get the formula for the derivative of the $y=x|x|$ function? I have this exercise:

(a) Sketch the graph of the function $f(x) = x|x|$.
(b) For what values of $x$ is f differentiable?
(c) Find a formula for $f'(x)$.

The sketching part was easy, since this function is basically $f(x)=x^2$, except that the part of the plot on the interval $(- \infty, 0)$ is mirrored against the $x$ axis.
The $b$ part was easy too, since the function is differentiable for every $x$ in the Reals domain, which probably should be substantiated by a reference to the theorem, that "if functions $f(x)$ and $g(x)$ are defined at a, then the function $fg$ is also defined at $a$".
But I have no idea how can I solve the third part about the formula of the derivative. I understand, that the formula is $f'(x) = 2|x|$, but how can I derive it from the definition of the derivative, which is $f'(a) = \lim_{x \to a}\frac{f(x) - f(a)}{x - a} => f'(x) = \lim_{x \to a}\frac{x|x| - a|a|}{x - a}$?
I tried to use the $a^2 - b^2 = (a - b)(a + b)$ formula for the $x|x| - a|a|$ expression, but it didn't work, since $x|x| - a|a| \neq (x - a)(x + a)$, if the x and a have different signs.
I tried to split the problem into 4 cases and got the results in the right part:

*

*$x > 0, a > 0 \implies f'(a) = 2a$, in detail: $\lim_{x \to a}\frac{x^2 - a^2}{x - a} = \frac{(x - a)(x + a)}{x - a} = 2a$ and the formula would be $f'(x) = 2x$

*$x > 0, a < 0 \implies f'(a) = a$, in detail: $\lim_{x \to a}\frac{x^2 - -a^2}{x - -a} = \frac{2a^2}{2a} = a$ and the formula of the derivative here would be $f'(x) = x$

*$x < 0, a > 0 \implies f'(a) = a$

*$x < 0, a < 0 \implies f'(a) = 2a$
This is definitely incorrect.
So could anyone provide any help here, please?
 A: If $a>0$, and $x$ gets very close to $a$, you only have to consider the case when $x>0$.
Similarly for $a<0$.
When $a=0$, $f(0)=0$.
$$\lim_{x \to 0} \frac{f(x)-f(0)}{x-0}=\lim_{x \to 0}\frac{f(x)}{x}=\lim_{x \to 0}|x|=0=2|0|$$
when $a<0$:
$$\lim_{x \to a}\frac{f(x)-f(a)}{x-a}=\lim_{x \to a}\frac{x(-x)-a(-a)}{x-a}=\lim_{x\to a}\frac{a^2-x^2}{x-a}=-2a$$
Remark:
Use Piyush's method for $a<0$, I am just helping you to find your mistake for getting $2a$.
Your reasoning for part $b$ is wrong. knowing $fg$ exists doens't imply $fg$ is differentiable. The working in $c$ justifies part $b$ actually that it is differentiable everywhere.
A: Write it as following 
$$f(x) = x^2 \quad x\in[0,\infty) \\ 
  f(x) = -x^2\quad x \in(-\infty,0)$$
It is differentiable everywhere. And the derivative is 
$$f'(x) = 2x \quad x\in[0,\infty) \\ 
  f'(x) = -2x\quad x \in(-\infty,0)$$
Edit: Limit at $x = 0$
$$\lim_{h \rightarrow 0^-}\frac{f(0)-f(0-h)}{h}=\lim_{h \rightarrow 0^-}\frac{h^2}{h}=0=\text{LHD} \\ 
\lim_{x \rightarrow 0^+}\frac{f(0+h)-f(0)}{h}=\lim_{x \rightarrow 0^+}\frac{h^2}{h}=0=\text{RHD} \\ \text{LHD} =\text{RHD}$$
This implies it is differentiable  at $0$
