Hi I was sorting an array with sort and don't know why/how/the order in which JavaScript is executing the code.
code below
arr = ["cc", "aa", "dd", "bb"];
console.log(arr);
fun = function() {
var re = arr;
console.log(re);
re = re.sort();
console.log(re);
};
fun();
I know that the sort() method changes the original array object but why when I console.log before the sort method am I not getting the original order of the array?
Can someone please explain JavaScript's execution order? I thought it executed top to bottom.
Thanks.
update: JSfiddle below