isSameTree = function (p, q) {
    // Check if both nodes are null (end of a branch in both trees)
    const areBothNodesNull = p == null && q == null;
    if (areBothNodesNull) return true;

    // Check if only one node is null (mismatch in tree structure)
    const isOnlyOneNodeNull = p == null || q == null;
    if (isOnlyOneNodeNull) return false;

    // Check if node values are equal (mismatch in node values)
    const doNodesHaveEqualValue = p.val == q.val;
    if (!doNodesHaveEqualValue) return false;

    // Recursively check left and right subtrees
    return dfs(p, q);
}
Check if both nodes are null (end of a branch in both trees)
@param {TreeNode} p
@param {TreeNode} q
@return {boolean}