---
# System prepended metadata

title: JavaScript binary tree node structure

---

# JavaScript binary tree node structure

```javascript=
function TreeNode(val, left, right) {
  this.val = (val===undefined ? 0 : val)
  this.left = (left===undefined ? null : left)
  this.right = (right===undefined ? null : right)
}

let t3 = new TreeNode(3)
let t2 = new TreeNode(2)
let t1 = new TreeNode(1, t2, t3)

console.log(t1);
```