DFS pre order. JS
Approach\nDepth first search.\n\nT: O(n)  S: O(n)\n\n\n\n# Code\n\nvar preorderTraversal = function (root, arr = []) {\n  DFS(root);\n  return arr;\n  function 
# Approach\nDepth first search.\n\nT: O(n)  S: O(n)\n\n\n\n# Code\n```\nvar preorderTraversal = function (root, arr = []) {\n  DFS(root);\n  return arr;\n  function DFS(node) {\n    if (!node) return;\n    arr.push(node.val);\n    DFS(node.left);\n    DFS(node.right);\n  }\n};\n\n```\n\n\nor\n\n# Code\n```\nvar preorderTraversal = function (root, arr = []) {\n  if (!root) return [];\n  arr.push(node.val);\n  preorderTraversal(root.left, arr);\n  preorderTraversal(root.right, arr);\n  return arr;\n}\n```\nor\n# Code\n```\nvar preorderTraversal = function (root, arr = []) {\n  if (!root) return arr;\n  return [root.val,...preorderTraversal(root.left, arr),...preorderTraversal(root.right, arr)];\n};\n```\n\n
['JavaScript']