It helps to understands how recursive calls works. function Node(val) { return { val, next: null }; } function LinkedList() { return { head: null, tail: null, add(val) { const node = new Node(val); if (!this.head) { this.head = node; this.tail = node…