You have defined the function on the range 0<=x<2. Following that, this function definition in Mathematica syntax matches only for the argument in that range. Then Piecewise is used to define the map. I suggest looking up Condition and Piecewise in the documentation for a full understanding.
f[x_ /; 0 <= x < 2] := Piecewise[{{0, x < 1}, {1, x < 2}}]
Plot[f[x], {x, -1, 3}, PlotStyle -> Thickness[.01]]