StringRepetitionOperator
DRAFT

Misconception:

In JavaScript, the multiplication operator can be used to multiply a String by a number. The result of such an expression is a new String that corresponds to the given String repeated the given number of times.

Incorrect

One can repeat a String by multiplying it with a number

Correct

One cannot repeat a String by multiplying it with a number

Correction
Here is what's right.

JavaScript’s multiplication operator only works for numbers. It does not support the repetition of Strings. To repeat a String a given number of times, one can use a loop.

Origin
Where could this misconception come from?

If students previously learned Python, they may inappropriately transfer this idea from Python (where such an operator exists) to JavaScript.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.