Reverse a Linked List in place
I'm not a big fan of your type-hinting comments.  Let JavaScript be JavaScript.  If you want typing, practice TypeScript instead.

I find it counterintuitive that the ListNode constructor takes its next parameter before its val parameter.  Putting val first is more natural (see my piDigits example below), and also allows next to be omitted for the last node in a list.

You can use the {val, next} syntactic shorthand.

As for the reverseLinkedList algorithm, there is too much code, with too many special cases.  The fact that you mention .next.next, reaching two elements ahead, is a sign that you aren't thinking about the loop invariant the right way.  You want the code to consider just the local situation at the head.

It's not really appropriate to explicitly set a variable to undefined; undefined is supposed to represent the fact that no assignment has taken place.  In any case, you should be more lenient than checking for … === undefined.

I find that it's nearly always unhelpful to use temp as a variable name or in a variable name.



const ListNode = (val, next) =&gt; { return {val, next}; };

const reverseLinkedList = (head) =&gt; {
    let newTail = null;
    while (head) {
        let next = head.next;
        head.next = newTail;
        newTail = head;
        head = next;
    }
    return newTail;
};



let piDigits = ListNode(3, ListNode(1, ListNode(4, ListNode(1, ListNode(5)))));
console.log(reverseLinkedList(piDigits));

let emptyList = null;
console.log(reverseLinkedList(emptyList));