The rules for hoisting are:
- Variable assignment takes precedence over function declaration
- Function declarations take precedence over variable declarations
So the order of the hoisting would be
Variable declaration -> Function declaration -> Variable assignment
Take a look at this article, basically, to quote the article, the reason this is happening is because:
Function declarations are hoisted over variable declarations but not over variable assignments.
In this section, it even has the exact same example as you gave in your question.
To sum up, your declaration of function x can't "overwrite" (hoist over) your variable assignment, but can "overwrite" your variable declaration.