Do while loop and the function given in 4 step 10


How does the line given make a function? Did I miss something?

On line 2 we see the following.

var getToDaChoppa = function(){

What is this? is it a function or a variable. This is not how I remember learning how to write a function.

This is the syntax I learned.

function nameOfMyFunction (Parameters) {
//Code goes here...

Can anyone explain this?


What you know is called function declaration. What is confusing is called function expression.
You want to know the biggest difference? How and when they are loaded.
If you are using and expression (with making function with var), function is loaded only after it's written in code and CAN NOT be called anywhere before. (You will see and examples later)
If you are using declaration, function is loaded before any code is run. (Again, examples will make it easier to understand)

// Function Expression
alert(foo()); // ERROR! foo wasn't loaded yet
var foo = function() { return 5; }

This wont work, because at the moment when foo() is called, it doesn't exist.

// Function Declaration
alert(foo()); // Alerts 5
function foo() { return 5; }

This will work, because as I said, declarations are loaded before any code is run.

Let me know if you need more explaining.