The full canvas drawing model
Think of the canvas as a single sheet of paper you repaint from scratch every frame. There is no "erase", you cover the old picture with a fresh background, then draw the new picture on top. This is why the "paint the whole screen black" step matters: without it, every previous frame would smudge into the next.
ctx.fillStyle = '#101018';
ctx.fillRect(0, 0, width, height); // clean slate
// ...draw players, coins, hazards here...
The context remembers a handful of "current" settings, fillStyle, font, textAlign: and every draw call uses whatever is currently set. Change a setting, then draw. This is different from most graphics APIs that pass the style into each call.
The finished game also draws with gradients (createLinearGradient+addColorStop) for the sky and ground, but the model is identical: set a paint, then draw.
Text alignment and centering
fillText(text, x, y) places text with x as the left edge and y as the vertical middle. To center a title horizontally, either set ctx.textAlign = 'center' and use width / 2, or, like the real game does for its simple title, just use width / 2 as the x and read the text as anchored there.
ctx.textAlign = 'center';
ctx.font = '40px sans-serif';
ctx.fillText('ENDLESS RUNNER', width / 2, height / 2 - 80);
ctx.fontsets the size and family, e.g.28px sans-serif.ctx.textAligncan be'left','center', or'right'.
The game fakes centering on its original title by centering the x and trusting the baseline, which is why every title line uses width / 2. When you're ready, textAlign = 'center' makes this exact.
Watch out: changing ctx.font affects every later fillText, so reset it between the title font and the HUD font.