You cannot do an assignation or call a function outside a function.
First snippet line 5 is a stand-alone assignment statement. Executable statements are not allowed outside of functions.
Second snippet line 4 is an initialization of a global, which is allowed.
Third snippet - everything is within a function, which is fine.