I am doing a simple javascript problem where I have to pass an array through a function and have the array reassigned a different value. How come when I pass through an array (or even any variable) I have to specifically reassign the array in order for it to change? Can't I just use the code in the function to use the parameter to do that for me? Here's my code:
<script>
var str = 'this is my sentence';
//Write a function called reverse that takes is given str as it's only argument and returns that string after it's been reversed
function reverse(x) {
x = x.split('').reverse().join('');
return x;
}
//returns with the text reversed, but str is still 'this is my sentence' and not the reversed version
</script>