reverse a linked list js

JavaScript
// O(n) time & O(n) space
function reverse(head) {
  if (!head || !head.next) {
    return head;
  }
  let tmp = reverse(head.next);
  head.next.next = head;
  head.next = undefined;
  return tmp;
}
function LinkedListNode(value) {
  this.value = value;
  this.next = null;
}
let head = new LinkedListNode(10)
head.next = new LinkedListNode(25)
head.next.next = new LinkedListNode(46)

// Recursive
const reverse = (head) => {
 if (!head || !head.next) {
   return head;
 }
 let temp = reverse(head.next);
 head.next.next = head;
 head.next = undefined;
 return temp;
}
head = reverse(head)
Source

Also in JavaScript: