Clear An HTML Canvas With JavaScript

I'm using `.clearRect()`js` to clear the contents of an HTML canvas element like this example which draws a square and then immediately clears it.

Notes
  • The values of `.clearRect()`` are:

    start x, start y, end x, end y

  • Using the `.width`` and `.height`` of the canvas automatically takes you do the end.

  • Which, when combined with setting the start x and start y to zero, clears the entire thing

Reference