Does hiding variables work in terms of blocks or line-by-line?
It depends on the programming language.  It's up to each language to specify whether this is legal or not, and what it means.

In many languages this would be legal.  It is called variable shadowing.