1

I am learning some javascript and I never got the idea of what is the difference between creating a function like this:

var justMe = function(param1, param2) {
     code code code;
};

And this:

function justMe(param1, param2) {
    code code code;
}

And why in the second example is the semi-colon is not requiered at the end, like in the first example?

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169
MoeSzislak
  • 137
  • 1
  • 4
  • 13
  • *"And why in the second example is the semi-colon is not requiered at the end, like in the first example?"*: In the first case you have an expression statement (an assignment expression to be precise), which always has to end with a semicolon. In the second case you have a function declaration, which does not. – Felix Kling May 04 '13 at 12:28
  • This is the way to Create a JavaScript Function function justMe(param1, param2) { code code code; } But this You assigned set of these String JustMe variable. var justMe = function(param1, param2) { code code code; }; try this sample var justMe = function(param1, param2) { return param1 + param2; }; alert(justMe); then you Get complete String inside justMe. **DEMO** [Link][1] [1]: http://jsfiddle.net/9tcSc/ – Akshay Joy May 04 '13 at 12:34

1 Answers1

0

I'll give it simply.

function justMe(param1, param2) {
    code code code;
}

Here you are declaring the function in it's original syntax.

var justMe = function(param1, param2) {
     code code code;
};

Here you are assigning a function body to a variable and hence you require the end semicolon.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91