We have to claim variables in advance?

also a funny thing is that this works too


function setup() {
  createCanvas(100,100);
  pg = createGraphics(100,100);  // claim variable like this
}

function draw() {
  pg.background(100);
  image(pg, 0, 0);
}

let pg;

as written above, it’s about the scope and not necessarily “in advance”.

2 Likes