function main() {
let canvas = document.getElementById("field");
let ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, ctx.width, ctx.height);
for(let i=0; i<600; i=i+10) {
ctx.moveTo(0+i, 0+i);
ctx.lineTo(20, 440);
ctx.stroke();
setTimeout(function() {
console.log(2);
}, 1000);
}
}
window.onload = main;
A function to be executed after the timer expires.