First, let’s see that Sin[x] and Sin[n x] are orthogonal functions:

Manipulate[
GraphicsRow[{Plot[{Sin[x],Sin[n*x]},{x,0,2 Pi}, PlotStyle -> Thick],Plot[Sin[n*x]*Sin[x],{x,0,2Pi}]}],{n,1,5,1}]

f[x_] := If[x<0,-1,+1];

(* a[n] *)
a[n_] =(2/2)*Integrate[f[x] Cos[n *Pi* x], {x,-1,1}]

(* b[n] *)
b[n_] = Integrate[f[x] Sin[n*Pi*x],{x,-1,1}]

fourier[nmax_,xx_]:= Sum[((2-2 Cos[n π])/(n π))*Sin[n*Pi*xx],{n,1,nmax}]

Manipulate[Plot[{f[x],fourier[nmax,x]},{x,-1,1},PlotStyle -> Thick, PlotRange -> {-1.3,1.3}, PlotLabel -> {"Terms", nmax},PerformanceGoal->"Quality"],{nmax,1,50,1}]

Manipulate[Plot[fourier[nmax,x],{x,-5,5},PlotStyle -> Thick, PlotRange -> {-1.3,1.3}, PlotLabel -> {"Terms", nmax},PerformanceGoal->"Quality"],{nmax,1,50,1}]

f2[x_] := x;

(* a[n] *)
a2[n_] =Integrate[f2[x] Cos[n *Pi* x], {x,-1,1}]

(* b[n] *)
b2[n_] = Integrate[f2[x] Sin[n*Pi*x],{x,-1,1}]

fourier2[nmax_,xx_]:= Sum[((-2 n π Cos[n π]+2 Sin[n π])/((n^2) (π^2)))*Sin[n*Pi*xx],{n,1,nmax}]

Manipulate[Plot[{f2[x],fourier2[nmax,x]},{x,-1,1},PlotStyle -> Thick, PlotRange -> {-1.3,1.3}, PlotLabel -> {"Terms", nmax},PerformanceGoal->"Quality"],{nmax,1,50,1}]

Manipulate[Plot[fourier2[nmax,x],{x,-5,5},PlotStyle -> Thick, PlotRange -> {-1.3,1.3}, PlotLabel -> {"Terms", nmax},PerformanceGoal->"Quality"],{nmax,1,50,1}]