Saturday, June 13, 2020

JavaScript blessings and curses

Can you spot the difference between the following two JavaScript lines:

ctx.fillstyle = "green";
ctx.fillStyle = "green";

The first line does not give you an error even tough ctx does not have a fillstyle field (note the small "s"), it just adds another field to ctx! Being not strongly typed is the blessing and curse of JS (more a curse when the code gets larger). When you use the first line you will get a black circle because black is the default color.


No comments: