Gradient vector for a function of two variables For the function $z = x^2 + y^2 , z = f(x,y)$
the gradient comes out to be $(2x,2y)$.
However since the function is in 3D , shouldn't the gradient also be a 3D vector?
How would the gradient change if $w = f(x,y,z) = x^2 + y^2 -z =0$?
Will it be $(2x,2y, -1)$?

If you define $f:\mathbb R^2\to\mathbb R$ as $f(x,y) = x^2 + y^2$, that's a two-dimensional function and its gradient is $\nabla f(x,y) = (2x, 2y)$.
When you write $z=f(x,y)$, what you are defining is a set in $\mathbb R^3$ which is known as the graph of $f$. Specifically, $\Gamma(f)=\{(x,y,z)\in\mathbb R^3:z=f(x,y)\}$. In this case, it's a paraboloid.
If you define another function $g:\mathbb R^3\to\mathbb R$ as $g(x,y,z) = f(x,y) - z = x^2+y^2-z$, then its gradient is $\nabla g(x,y,z) = (2x, 2y, -1)$. Now, the zero level curve for $g$, $\{(x,y,z)\in\mathbb R^3:g(x,y,z)=0\}$, coincides with $\Gamma(f)$ and $\nabla g$ is orthogonal to it.
