How to write functions


My code works but I have a question about the different ways to write a function.

voidLastTransaction: function () {

This code only worked when I wrote the function like you see above, yet in other exercises I have see a function written like:

var voidLastTransaction = function() {


function voidLastTransaction () {

How come these two forms of function don't work in this problem and when should one use these other forms of writing a function statement?



voidLastTransaction: function () {}

In cashRegister object
you defined a couple of properties separated from eachother by comma ,

Each property consisted of a property-key and its associated Value
For instance you had
a total property with property-key total** and its associated number Value 0
you also had to create
a voidLastTransaction property with property-key voidLastTransaction and its associated function Value _function () { }

As the property voidLastTransaction has an associated function-Value

voidLastTransaction is called a METHOD



var voidLastTransaction = function() {};

( take notice:: you end the definition with a semi-colon ; )

Here you define a variable voidLastTransaction
to which you assign a so-called anonymous function

To call this anonymous function
you will have to append a pair-of-parentheses-() to the variable name



function voidLastTransaction () {}

voidLastTransaction ()