Depth Test

To use the depth test, enable it during initialization.

gl.enable(gl.DEPTH_TEST);

And clear the depth buffer along with the color buffer during rendering.

gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

If necessary, depth writes disables separately from depth tests.

gl.depthMask(gl.TRUE);

gl.depthMask(gl.FALSE);

The Depth Test is used in almost every GL application. Only the most trivial of demonstrations overlook it.