Drawing Basics
Stroke Path
A path begins empty, receives points, and then stroke paints a polyline through those points.
Program
Canvas path methods build an invisible path. The path becomes visible only when a paint method such as stroke is called.
stroke_path.html
Visuals: captured from real browser rendering
<canvas id="stage" width="360" height="210"></canvas>
<script>
const ctx = stage.getContext("2d");
ctx.strokeStyle = "#1d4ed8";
ctx.lineWidth = 8;
ctx.beginPath();
ctx.moveTo(40, 160);
ctx.lineTo(140, 70);
ctx.lineTo(260, 120);
ctx.stroke();
</script>
Start a new path.

beginPath resets geometry but does not paint pixels. Move the path cursor to the first point.

moveTo positions the cursor without drawing. Add line segments to the path.

lineTo extends the path; stroke is still needed to paint it. Paint the stroked path.

stroke paints the accumulated path geometry.
path
A canvas path is geometry collected before painting.
stroke
stroke paints the outline of the current path.