A square wave can be represented by a Fourier series$$\text{for a square wave of period T, }\optbreak{}f(x)=\frac{4}{\pi}\sum_{n=1,3,5,...}^{\infty}{\sin{\frac{n\pi x}{T}}}$$. As you increase the number of terms in the series, the approximation becomes better, but the corresponding frequency spectrum includes higher frequencies.
The figure below shows the frequency spectrum, $R(j\omega)$, for the Fourier series of square wave and the corresponding time domain signal. Also shown is the sampled spectrum, $R^*(j\omega)$ for that signal and the time-domain signal reconstructed using the sampled spectrum.
Use the controls to change the number of terms in the series and change sampling frequency, $\omega_s$