Let $f:\mathbb{R}^n\to \mathbb{R}$ be a smooth function. Then for any regular value $a\in \mathbb{R}$ of $f$, its level set $f^{-1}(a)$ is orientable: the gradient of $f$ is nowhere tangent to $f^{-1}(a)$, so it determines an orientation on $f^{-1}(a)$. Now suppose $a$ is a critical value of $f$. Then $f^{-1}(a)$ is may not even be a manifold, but however let us assume that it is an embedded submanifold of $\mathbb{R}^n$. Is there such an example with $f^{-1}(a)$ nonorientable? (I've seen that a closed hypersurface of $\mathbb{R}^n$ is always orientable, so $f^{-1}(a)$ must not be compact.)
Or, more generally, if $f:M\to\mathbb{R}$ is a smooth function on a smooth manifold, can $f^{-1}(a)$ with $a$ a critical value of $f$, be a nonorientable embedded submanifold?
Edit. As in the comment, this is true, by considering an embedding $g$ of $\mathbb{RP}^2$ in $\mathbb{R}^4$, and choosing a smooth function $f:\mathbb{R}^4\to \mathbb{R}$ such that $f^{-1}(0)$ is the image of $g$.
Now I'm curious, for $f:\mathbb{R}^n\to \mathbb{R}$ a smooth function, can $f^{-1}(a)$ with $a$ a critical value of $f$, be a nonorientable embedded hypersurface?