JavaScript30 - Day 8

By Camilla Krag Jensen naxoc |

Day 8 of #javascript30 is playing around with canvas and drawing colorful things in the browser.

You don't actually draw on the the <canvas> - you draw on the 'context' that you get from the canvas - which can be 2D or 3D. Todays lesson is focusing on 2D and you can do a ton of cool stuff with that, so go check out the list of functions that CanvasRenderingContext2D offers. Lines, shapes, text and so on.

What made todays lesson super cool is the use of a variable that is used to increment the hue on the lines we are drawing by setting its strokeStyle. This made it so that I was not just drawing a monochrome line, but a line in all the colors of the rainbow. UNICORN BOWELS!

Unicorn Bowels

Destructuring assignment

In JavaScript the equivalent to PHP's list() is the destructuring assignment. So the idea is that you can assign values to variables from an array like so:

var a, b, rest;
[a, b] = [10, 20];
console.log(a); // 10
console.log(b); // 20

I'm not a big fan of that syntax. Not in PHP either. I have yet to see a case where it makes a ton of sense.