Let $X = A \cup B$, where $A$ and $B$ are subspaces of $X$. let $f: X \to Y$; suppose that the restricted functions $f\upharpoonright A:A\to Y$ and $f\upharpoonright B:B\to Y$ are continuous. Show that if both $A$ and $B$ are closed in $X$, then $f$ is continuous.
How does using h and g, as arbitrary functions in the hint below work?