// this is function declaration in JavaScript
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function
function myFunction (/* args */) { /* body */ }
// this is function expression
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function
const/var/let myFunction = function myFunction(/* args */) { /* body */ }
// this is basically (unnamed) function expression, defining property `f1` on global object `window`
window.f1 = function (/* args */) { /* body */ }
If you change the third approach to the second one, it will become bound to some scope (the block, where it's going to be put). While the third one is always global (it is available from anywhere).
Note that you can also declare function in the global scope, using 1st and 2nd approaches. For example:
<head>
<script>function myFunction() {/* body */}</script>
</head>
Please, look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#Implicit_globals_and_outer_function_scope