LESSON 23 / 75·2 min readFoundation

Linked list in JavaScript

Should knowConcept lesson
01 Understand02 Recall03 Prepare

Node structure

JavaScript
class ListNode {
  constructor(val) {
    this.val = val;
    this.next = null;
  }
}

Problems to practice

  • Reverse Linked List
  • Middle of Linked List
  • Detect Cycle
  • Remove Nth Node from End
  • Merge Two Sorted Lists
  • Intersection of Two Linked Lists

Example: reverse linked list

JavaScript
function reverseList(head) {
  let prev = null;
  let curr = head;

  while (curr) {
    const next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
  }

  return prev;
}

PAUSE & RECALL

Can you explain it without the notes?

Linked list in JavaScript

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Node structure

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Stack and queue in JavaScript

Adapted from 16_DSA_JAVASCRIPT.md · “4. Linked list in JavaScript”. Examples are study fragments; framework behavior can depend on your version.