A function declaration is made of function keyword, followed by an obligatory function name, a list of parameters in a pair of parenthesis (para1, ..., paramN) and a pair of curly braces {...} that delimits the body code.
// function declaration
function isEven(num) {
return num % 2 === 0;
}
isEven(24); // => true //Execution of function
isEven(11); // => false
Here you can see the function isEven{..} function declaration that defines isEven function, which determines if a number is even.
Where as greet(function(){}); is nothing but a greet function call with a callback function passed and defined in it once the greet function is executed if you want something to happen after execution that you can handle with callback function for this to work
function greet() {
this.firstname = 'johan',
this.lastname = 'Don'
console.log(this.firstname + ' ' + this.lastname);
//...
//...
}
will change as
function greet(callBack) {//function as parameter received
this.firstname = 'johan',
this.lastname = 'Don'
console.log(this.firstname + ' ' + this.lastname);
//...
//...
callBack()//callback function called
}
callback function called will execute the code you have done in callback.
refer link for understanding callback