In var rgba = "rgba(0, 0, " + b + ", 0.5)";
the double quotes are not around + b +
but around rgba(0, 0,
and , 0.5)
, forming two fixed parts of this string expression where the value of b
is inserted (after automatic conversion to string).
This expression builds a string like rgba(0, 0, 50, 0.5)
(when i
is 2, leading to a b
of 50) and stores it in the rgba
variable.
EDIT
Let's insert some linebreaks for readability:
var rgba = "rgba(0, 0, " +
b +
", 0.5)";
The expression consists of three parts that are added together: a string constant ("rgba(0, 0, "), the (number-type) variable b
and another string constant (", 0.5)"). The result will be a string.
The +
operator can be an arithmetic operator or (as is used here) a string concatenation operator.
Because you are adding a string and a number, you are using string concatenation (instead of arithmetic addition) and the number is converted to a string first. The result is a string where the third part of the expression is added to.
The result ("rgba(...)"
) is assigned to c.fillStyle
, which interprets it as a color.