Iterative and Recursive DFS JS Solutions
\n// Iterative DFS Solution\nvar preorderTraversal = function(root) {\n    if (!root) return [];\n    let stack = [], res = [];\n    stack.push(root);\n    whil
```\n// Iterative DFS Solution\nvar preorderTraversal = function(root) {\n    if (!root) return [];\n    let stack = [], res = [];\n    stack.push(root);\n    while (stack.length) {\n        let node = stack.pop();\n        res.push(node.val);\n        if (node.right) stack.push(node.right);\n        if (node.left) stack.push(node.left);\n    }\n    return res;\n\t// Time Complexity: O(n)\n    // Space Complexity: O(n)\n};\n```\n\n```\n// Recursive DFS Solution\nvar preorderTraversal = function(root, res = []) {\n    if (!root) return [];\n    res.push(root.val);\n    if (root.left) preorderTraversal(root.left, res);\n    if (root.right) preorderTraversal(root.right, res);\n    return res;\n    // Time Complexity: O(n)\n    // Space Complexity: O(n)\n}\n```
['JavaScript']