Functions (syntax)


#1

Hi guys, does anybody now what is the difference between these 2 ways to use functions:

function myFunctionName (parameter) {
 //do something
};

and

var myFunctionMame = function (parameter) {
 //do something
};

#2

FROM MDN

The function declaration

(function statement)

function name([param,[, param,[..., param]]]) {
   [statements]
}

name
The function name.

param
The name of an argument to be passed to the function. A function can have up to 255 arguments.

statements
The statements comprising the body of the function.

The function Expression

The function keyword can be used to define a function inside an expression.

function name([param,[, param,[..., param]]]) {
   [statements]
}

Parameters

name
The function name. Can be omitted, in which case the function is anonymous. The name is only local to the function body.

paramN
The name of an argument to be passed to the function.

statements
The statements which comprise the body of the function.

Description
A function expression is very similar to and has almost the same syntax as a function statement (see function statement for details). The main difference between a function expression and a function statement is the function name, which can be omitted in function expressions to create anonymous functions. A function expression can be used as a IIFE (Immediately Invoked Function Expression) which runs as soon as it is defined. See also the chapter about functions for more information.

var myFunctionMame = function (parameter) {
 //do something
};

Functions
Function Statements
Function expression


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.