I was writing some canvas code to draw a circle, but it never got painted. At last I found out it was because I had typed Math.Pi instead of Math.PI.
In Chrome Dev Tools I could see that Math.Pi was undefined, but it never threw any exceptions. Is this a bug in Chrome or is it actually legal to do calculations on undefineds?
Here is my code:
ctx.save();
ctx.lineWidth = 2;
ctx.fillStyle = '#FF0000';
ctx.beginPath();
ctx.arc(can.x, can.y, 15, 0, Math.Pi * 2, true);
ctx.fill();
ctx.restore();
ctx refers to canvas.getContext("2d");.
undefined * 2evaluates toNaN, and the canvas 2D context specification says:So, a
ctx.arccall with an argument ofNaNmeans that the call is silently ignored (i.e. nothing is drawn), rather than an error is thrown.