What IS a function.
Broadly speaking, a function is a mapping between two sets. (Equivalently, it can be defined as a set of ordered pairs with the condition the first terms of the pairs are distinct. But I think viewing it as such is confusing to students to learn). So I repeat, a function is a mapping between two sets.
I think the two most common misconceptions students make are to: i) underestimate how important identifying specifically what the sets are in defining the function and ii) overestimate the "rule" (if any) of the mapping.
i) A function must have its domain defined and if two functions have different domains they are different functions. If $f(n) = \sum\limits_{i=1}^n = \frac {n(n+1)}{2}$ is a function mapping the set of positive integers to the sums of positive integers, and $g(x) = \frac 12x^2 + \frac 12 x= \frac {x(x+1)}2$ is a quadratic polynomial on the real numbers, these are not the same, even though the take on the same values and the values for which they are both defined. That one is defined for other values makes all the difference.
ii) And although we can say that $g(x)$ extends $f(n)$ int the reals we can not say it is the extension. Another function, $h(x) = \frac 12(92(\lfloor x \rfloor - x)^{32} + x^2 + \lfloor x \rfloor + e^{x - \lfloor x \rfloor} - 1)$ is also an extension of $f(n)$ to the reals. $f(n) = g(x)$ and $f(n) = h(x)$ on every point where all three functions exist. So there is no justification that one function is the same and the other is not.
This means that $f(x) = \frac {x^2 - 4}{x-2}$ is undefined at $x = 2$. Its domain is $\mathbb R\setminus \{2\}$. $g(x) = x+2$ is defined at $x=2$ and its domain is $\mathbb R$. These two functions have different domains, so they are different functions.
Even though $f(x) = x+2;x\ne 2$ it should no more be considered to be the same as $g(x) = x+2; x \in \mathbb R$ then it should be considered to be the same as $h(x) = x+2; x \ne 2: h(x) = \frac 1{x-3}; x = 2$ (the function that is equal to $x+2$ when $x\ne 2$ but which equals $-1$ if $x$ does equal $2$).
========
Not.
At $x = 2$ the function is undefined as it involves dividing by zero.
"But since $f(x)$ can be simplified to:
$f(x)=x+2$"
No. $f(x)$ can NOT be simplified to $f(x) = x+2$.
$g(x) = x+2$ is a completely different function than $f(x) = \frac{x^2 -4}{x-2}$. $f(x)$ be simplified to $f:\mathbb R\setminus\{2\} \rightarrow \mathbb R$ via $f(x) = x+2$ but that has a different domain than $g: \mathbb R \rightarrow \mathbb R$ via $g(x) = x+2$. The two function may take on the exact same values on the points that are mutually in their domains, but because the do have different domains they are different functions.