The derivative of $f(x)=x|x|$ We are tasked to compute the derivative of $f(x)=x|x|$.
$$f(x) = \begin{cases} 
      x^2 & x> 0 \\
      0 & x=0\\
      -x^2 & x<0 
   \end{cases}
$$
We use the product rule to calculate the derivative of $f(x)$.
$$f'(x)=x(|x|)'+|x|$$
We know that $$(|x|)'= \begin{cases} 
      1 & x> 0 \\
      \text{undefined}& x=0\\
      -1 & x<0 
   \end{cases}$$
So $$f'(x) =\begin{cases} 
      2x & x> 0 \\
      \text{undefined}& x=0\\
      -2x & x<0 
\end{cases}$$
But if we take the limit as $x \to 0$, we find the left limit and the right limit equal $0$.
Then$$f'(x) =\begin{cases} 
      2x & x> 0 \\
      0& x=0\\
      -2x & x<0
\end{cases}  $$
 A: An alternate approach would be to use the product rule and the fact that $\dfrac{d}{dx}|x|=\dfrac{x}{|x|}=\dfrac{|x|}{x}$ for $x\ne0$
$\dfrac{d}{dx}(x|x|)=1\cdot|x|+x\cdot\dfrac{|x|}{x}=2|x|$ for $x\ne0$.
Note that the derivative of $|x|$ can be easily found using the limit definition.
\begin{eqnarray}
\frac{d}{dx}|x|&=&\lim_{h\to0}\frac{|x+h|-|x|}{h}\\
&=&\lim_{h\to0}\frac{|x+h|-|x|}{h}\cdot\frac{|x+h|+|x|}{|x+h|+|x|}\\
&=&\lim_{h\to0}\frac{|x+h|^2-|x|^2}{h(|x+h|+|x|)}\\
&=&\lim_{h\to0}\frac{(x+h)^2-(x)^2}{h(|x+h|+|x|)}\\
&=&\lim_{h\to0}\frac{2xh+h^2}{h(|x+h|+|x|)}\\
&=&\lim_{h\to0}\frac{2x+h}{|x+h|+|x|}\\
&=&\frac{x}{|x|}\quad\text{for }x\ne0
\end{eqnarray}
A: Your calculation of $f'(x)$ is fine for $x > 0$ and $x < 0$, but not for $x = 0$.  You wrote "if we take the limit as $x \to 0$," but you didn't say what you're taking the limit of.  I'm guessing you took the limit of $f'(x)$.  But if that's what you did, then you were computing $\lim_{x \to 0} f'(x)$, which is not the same as computing $f'(0)$.  To compute $f'(0)$, us the definition of derivative:
$$
f'(0) = \lim_{h \to 0} \frac{f(0+h) - f(0)}{h} = \lim_{h \to 0} \frac{h|h| - 0}{h} = \lim_{h \to 0} |h| = 0.
$$
