Preorder traversal
A binary tree traversal pattern using depth first search that first visits the current node, then the left node, then the right node.
function preorder(node) {
if (node) {
console.log(node.val);
preorder(node.left);
preorder(node.right);
}
}