I've a small node.js code that is not working as expected.
There is a for-loop in my code and at the end of for-loop, I'm trying to print the result, but the output that I'm expecting is not matching the output that I'm getting. please let me know on how can I fix it.
Here is my code:
var ttall = "";
var ttall_assists = "";
var total="";
for (var i = 0; i < 3; i++) {
ttall += 'AAA' + i;
ttall_assists += 'BBB' + i + '\n';
total+=`${ttall} ${ttall_assists}`;
}
console.log(`${total}`);
Expected output is:
AAA0 BBB0
AAA1 BBB1
AAA2 BBB2
Currently the output that I get is:
AAA0 BBB0
AAA0AAA1 BBB0
BBB1
AAA0AAA1AAA2 BBB0
BBB1
BBB2
console.log(`AAA${i} BBB${i}`);
, there is no reason to be creating all those extra variables nor tracking the result in a buffer. All of those extra operations are creating unnecessary overhead.