Write JavaScript code to reverse a linked list