I want to reverse a string without build in function such split, reverse and join, i have try the code from here https://stackoverflow.com/a/51751393/8070090 , but i am not realy understand what's the code do on the fourth line, i need more explanations on the fourth line. This is my code with some explanation
function reverseString(str) {
reverseIt = [];
for (i = 0; i < str.length; i++) {
reverseIt = str[i] + reverseIt; // the first way that works
// reverseIt = str[i] + []; // first.. i assume the variable "reverseIt" is equal to "[]", but the result from this line is not equal to the line above
// reverseIt = str[i] + ''; // then i try this way with assume the variable reverseIt is empty string (""), but the result from this line not produce the expected result
// var testing = []; // and then i try to make an empty array variable again
// reverseIt = str[i] + testing; // and try to add the variable above, but this still not realy produce the expected result
/*
So the questions.., why the first way can works..?, what's actualy the code on that line do..?
*/
}
return reverseIt;
}
console.log(reverseString('Javascript'));