We need one more thing that will enable us to draw on the canvas. We need a reference to the "graphics context", by writing this line:
let g2 = cnv.getContext("2d");
g2
is my own preference, for historical reasons. It is useful though because it is short and distinctive. Other people tend to call it ctx
instead.The parameter here is specifying 2 dimensions (it must be a lower case d though). The point is that there are other possibilities but they are all much more difficult to understand so we will leave it at that for now. Once you have mastered the 2d context you might look into more clever things.
The context has several properties (data values) we will need to set, such as colour for drawing and it has many functions for drawing different shapes. We will get to those soon.