var dollar = '$';
for (var i=1; i <= 6; i++) {
console.log(dollar);
dollar += '$';
}
I just start learning javascript, please help to explain why the script can print like this. Thx for help
$
$$
$$$
$$$$
$$$$$
$$$$$$
var dollar = '$';
for (var i=1; i <= 6; i++) {
console.log(dollar);
dollar += '$';
}
I just start learning javascript, please help to explain why the script can print like this. Thx for help
$
$$
$$$
$$$$
$$$$$
$$$$$$
dollar += '$';
is equal to
dollar = dollar + '$';
so first round dollar is equal to "$", so you will log it as it is, then you add another dollar to it. in next round you will see it "$$". like wise it comes to 6 dollar signs at the end, because you iterate it up to 6.