The first executable line in a function file must be the function definition line. MATLAB kindly pre-populates the editor window with the expected syntax if you ask to create a new function file.
Variables in a function file are local to the function (their scope is limited to the function) while variables in a script file are recognized in the Command Window.