What Is a Node in a Linked List?
A node is the fundamental building block of a linked list. Instead of storing all elements inside one continuous structure like an array, a linked list stores each element inside its own node.
A node normally contains two important parts: the data it stores and a reference that identifies another node.
+-------------+-------------+
| data | next |
+-------------+-------------+
10 ↓
Node 2
In a singly linked list, the reference is called next because it points
to the next node in the sequence.
Basic Linked List Node Structure
A simple node can be represented with a class containing a value and a
next property.
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
const node = new Node(10);
console.log(node.value);
// 10
console.log(node.next);
// null
When the node is first created, its next reference is usually
null because it is not connected to another node yet.
The Two Main Parts of a Node
1. Data
The data portion stores the actual value associated with the node. It could be a number, string, object, or another application-specific value.
const numberNode = new Node(100);
const nameNode = new Node("Abhinash");
console.log(numberNode.value);
// 100
console.log(nameNode.value);
// Abhinash
2. Reference
The reference identifies another node. In a singly linked list, the
next reference points to the next node.
const first = new Node(10);
const second = new Node(20);
first.next = second;
console.log(first.next.value);
// 20
The first node does not contain the second node's data directly. Instead, it stores a reference that allows the second node to be reached.
How Nodes Connect
A linked list is formed when the reference in one node points to another node.
Node A Node B Node C
+------+ +------+ +------+
| 10 | -----> | 20 | -----> | 30 |
+------+ +------+ +------+
|
↓
null
The nodes together create a sequence even though each node is a separate object.
What Is the Head Node?
The head is a reference to the first node in a linked list. It provides the starting point for traversing the structure.
head
↓
[10] → [20] → [30] → null
If the head is lost and no other reference can reach the first node, the remaining nodes may become inaccessible to the list.
What Is the Last Node?
In a standard singly linked list, the final node is the node whose
next reference is null.
[10] → [20] → [30] → null
↑
last node
The final node does not point to another node, which marks the end of the list.
Connecting Two Nodes
Two nodes become connected when the first node's next reference is
assigned to the second node.
const first = new Node(10);
const second = new Node(20);
first.next = second;
The structure is now:
first
↓
[10] → [20] → null
Creating Multiple Nodes
Multiple nodes can be created and connected to form a complete singly linked list.
const first = new Node(10);
const second = new Node(20);
const third = new Node(30);
const fourth = new Node(40);
first.next = second;
second.next = third;
third.next = fourth;
The resulting structure is:
first
↓
10 → 20 → 30 → 40 → null
Traversing Nodes
Traversal means starting from the head and repeatedly following the
next reference until the final node is reached.
function traverse(head) {
let current = head;
while (current !== null) {
console.log(current.value);
current = current.next;
}
}
The current reference changes during traversal, while the original
head remains unchanged.
Why Use a Current Reference?
A common linked-list pattern is to use a temporary reference such as
current. This lets the algorithm move through the list without losing
the reference to the first node.
let current = head;
while (current !== null) {
// Work with current node.
current = current.next;
}
Directly moving the head during traversal would change the starting reference and make it difficult to access the complete list afterward.
Changing a Node's Value
The value stored in a node can be updated without changing its connection to the rest of the list.
const first = new Node(10);
const second = new Node(20);
first.next = second;
first.value = 15;
console.log(first.value);
// 15
console.log(first.next.value);
// 20
Updating the value does not change the next reference.
Changing a Node's Reference
Updating next changes the structure of the linked list. This is the
foundation of insertion, deletion, and reversal operations.
const first = new Node(10);
const second = new Node(20);
const third = new Node(30);
first.next = second;
second.next = third;
first.next = third;
The structure changes from:
10 → 20 → 30
to:
10 → 30
The node containing 20 still exists as an object, but it is no longer
reachable from the head through this chain.
Node References and Insertion
Inserting a node requires changing references carefully. Suppose we want to insert
20 between 10 and 30.
Before:
10 → 30
New node:
20
First, connect the new node to the existing next node. Then connect the previous node to the new node.
newNode.next = previous.next;
previous.next = newNode;
The final structure becomes:
10 → 20 → 30
Why the Order of Reference Updates Matters
Consider the list:
10 → 30
If the new node is connected correctly:
newNode.next = previous.next;
previous.next = newNode;
the original connection to 30 is preserved. Reversing the order without
saving the required reference can accidentally disconnect part of the list.
Node References and Deletion
Deleting a node from a singly linked list usually means changing the previous node's
next reference so that it skips the node being removed.
Before:
10 → 20 → 30
Delete 20:
10 → 30
previous.next = nodeToDelete.next;
The node containing 20 is removed from the linked-list chain because
no node in that chain points to it anymore.
Node References and Reversal
Reversing a singly linked list means changing every node's next
reference so that the links point in the opposite direction.
Before:
10 → 20 → 30 → null
After:
null ← 10 ← 20 ← 30
↑
head
The algorithm must save the original next node before reversing the current reference.
let previous = null;
let current = head;
while (current !== null) {
const next = current.next;
current.next = previous;
previous = current;
current = next;
}
Node vs Linked List
A node is an individual building block. A linked list is the complete structure created by connecting nodes.
| Concept | Meaning |
|---|---|
| Node | Individual element containing data and references |
| Head | Reference to the first node |
| Tail | Reference to the final node when maintained |
| Next | Reference to the next node |
| Linked list | Collection of connected nodes |
Nodes in a Doubly Linked List
A doubly linked list extends the node structure by storing both a
next and a previous reference.
+----------+-------+----------+
| previous | value | next |
+----------+-------+----------+
↑ ↓
previous node next node
This allows traversal in both directions but requires additional memory and more reference updates during modifications.
Nodes in a Circular Linked List
In a circular linked list, the final node does not point to null.
Instead, it points back to another node, commonly the head.
head
↓
10 → 20 → 30
↑ ↓
└─────────┘
Because there is no null endpoint, traversal must use a different
stopping condition to avoid an infinite loop.
Node Memory Overhead
A linked-list node stores more than just the actual value. It also needs one or more references to other nodes.
Singly linked node:
[data | next]
Doubly linked node:
[previous | data | next]
This reference storage is one reason linked lists can require more memory per element than arrays.
Node Traversal Complexity
Traversing a linked list requires visiting nodes one by one. If there are
n nodes, a complete traversal takes O(n) time.
| Operation | Complexity |
|---|---|
| Create one node | O(1) |
| Read known node | O(1) |
| Traverse all nodes | O(n) |
| Find a value | O(n) |
| Insert after known node | O(1) |
| Delete after known predecessor | O(1) |
Common Node Manipulation Mistakes
Overwriting the Next Reference
If the current node's next reference is overwritten before saving the
original next node, the rest of the list may become inaccessible.
Losing the Head
The head is the entry point into the list. Changing it unnecessarily can make the original chain difficult or impossible to reach.
Forgetting Null Checks
Before accessing current.next, make sure current is not
null. This is especially important when processing empty or short lists.
Creating an Accidental Cycle
Incorrect reference assignments can cause a node to point back to an earlier node.
Traversal may then continue indefinitely instead of reaching null.
Practical Example: Task Nodes
Nodes can represent many kinds of application data. For example, a simple task sequence can be represented using linked-list nodes.
class TaskNode {
constructor(title) {
this.title = title;
this.next = null;
}
}
const loginTask = new TaskNode("Implement login");
const testTask = new TaskNode("Test login");
const deployTask = new TaskNode("Deploy application");
loginTask.next = testTask;
testTask.next = deployTask;
let current = loginTask;
while (current !== null) {
console.log(current.title);
current = current.next;
}
// Implement login
// Test login
// Deploy application
The node structure can contain application-specific properties while still using the same linked-node concept.
Why Nodes Are Important in Data Structures
Understanding nodes is important because many data structures use node-based organization. Linked lists, trees, graphs, and several specialized structures represent relationships through references between objects or records.
Once the relationship between data and references is clear, operations such as insertion, deletion, traversal, and reversal become easier to understand.
Key Takeaways
- A node is the basic building block of a linked list.
- A singly linked-list node contains data and a next reference.
- The head identifies the first node.
- The final node normally points to null.
- Nodes are connected by assigning references between them.
- Traversal follows the next reference from one node to another.
- Changing references is the foundation of linked-list insertion and deletion.
- Reversing a list requires carefully changing each node's next reference.
- Doubly linked-list nodes additionally contain a previous reference.
- Correct reference management is essential to avoid losing nodes or creating cycles.