My solution is first looking for the left most node, at the same time push node.val into result. Until finding a null node, go to the right node.

```
var preorderTraversal = function(root) {
if (root === null)
return [];
var result = [], stack = [];
while(root != null || stack.length != 0){
while(root != null){
result.push(root.val);
stack.push(root);
root = root.left;
}
root = stack.pop();
root = root.right;
}
return result;
};
```