I’m trying to understand a palindrome problem and I have written the code below. Why does .join not work by itself but works when embedded within a console log?
var str = 'hello dave';
var chars = str.split('');
console.log(chars);
chars.reverse();
console.log(chars);
chars.join(''); // Why does this step not result in the joined Array being print below?
console.log(chars); // Why does it not produce the joing step above.
console.log(chars.join('')); //Why does including it in a console log produce the correct output?
//This is the output from the above code
> Array ["h", "e", "l", "l", "o", " ", "d", "a", "v", "e"]
> Array ["e", "v", "a", "d", " ", "o", "l", "l", "e", "h"]
> Array ["e", "v", "a", "d", " ", "o", "l", "l", "e", "h"]
> "evad olleh"