Resizing a canvas is unusual, because setting the width/height of a canvas completely erases it.
If your canvas isn’t animating, you can just redraw after resizing. Depending on what you’re drawing, working in percentages instead of pixel values can make things easier.
If you hit the “Try it out…” button, go into fullscreen and resize your browser window you’ll see things in action.
This will output either x, y or z. It works by looking up a random index of an inline array. I find this great for quick prototyping – probably not something you want to be using outside throw away code… Hit the “Try it out…” button and open your dev console.