Your first code snippet is not valid - it only works within an object; example:
var object = { myFunction: function(variable) { } }; // object.myFunction();
Basically there are two ways to define a function ins JavaScript:
function myFunction(variable) { } var myFunction = function(variable) { };
The difference is: The first type of declaration uses the function statement and therefore allows you to use the function before it has been declared. Example:
console.log(myFunction()); // prints test function myFunction(variable) { return "test"; }
Read more about it here.
This is not possible with the second type of function declaration, which assigns an anonymous function to a variable. The function can't be used before the variable has been declared.
intdon't exist in JS (that's invalid too).{ <<right here>> }is an object literal andmyFunctionis a property of it, holding a function as value. Still, in the first case you have a function expression and in the second one a function declaration and the differences between those two have been thoroughly discussed before.