• remember = means assign NOT equal to like in math class

See the Pen Example Code by LSU DDEM ( @lsuddem) on CodePen.

https://codepen.io/lsuddem/pen/wXdQOE

  • A declaration special case:
let xValue = 1;

function setup() {
  let xValue = 21;
}
  • we can declare a variable with the same name twice with a function becuase of scope
  • but we don’t really want to
  • If you are declaring a number of variables without immediately initializing them, you can save some vertical space in your code editor by declaring them all on the same line while using a single let keyword. The example below declares four different variables all on one line, separated by commas:
let circleX, circleY, speed, jumpHeight;

Fixed Values vs. Changeable Values

See the Pen Example Code by LSU DDEM ( @lsuddem) on CodePen.

https://codepen.io/lsuddem/pen/BVRVYL

System Variables

See the Pen Example Code by LSU DDEM ( @lsuddem) on CodePen.

https://codepen.io/lsuddem/pen/OEmaYw

Variable Use
mouseX current location of mouse on the canvas’ X axis
mouseY current location of mouse on the canvas’ Y axis
pmouseX previous location of mouse on the canvas’ X axis
pmouseY previous location of mouse on the canvas’ Y axis
Variable Use
key current key pressed (ASCII keys only)
keyCode current special key pressed (ENTER, UP_ARROW, etc.)
width current width of the canvas in pixels
height current height of the canvas in pixels

Boolean System Variables

Variable Use
mouseIsPressed boolean - contains “true” if mouse pressed, “false” if not
keyIsPressed boolean - contains “true” if any key pressed, “false” if not

Global Scope vs. Local Scope

See the Pen Example Code by LSU DDEM ( @lsuddem) on CodePen.

https://codepen.io/lsuddem/pen/joxoqe