0

I've been reading up and the different types of functions I can use in JavaScript. Many developers seem to agree that Object Literal Functions:

var hotel = {
  name: "Quay",
  rooms: 40,
  booked: 25,
  checkAvailability: function() {
    return this.rooms - this.booked;
  }
 };

and

function getArea(width, height) {
     return width * height;
}

are the best functions to use. Do some of the seasoned JavaScript developers on stack over flow feel the sam? I've read that I should not create global variables, and global functions.

My last question is, how do I know which function I should implement in my code? I'm kind of confusued, and could use some help. Thank you.

  • 1
    This has already been covered [here](http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname) – enifeder Apr 19 '16 at 22:23
  • 1
    This isn't really a good question for SO. The answer, as in so many of these kinds of questions, is: it depends. Nor are these two the only options. Or even \*BLATANT OPINION WARNING\* the best options. – Jared Smith Apr 19 '16 at 22:24
  • Thank you enifeder. Much appreciated. –  Apr 19 '16 at 22:24
  • 1
    Unless you consider ES6 and `eval`, those are the *only* ways to create a function, and yes you should use them (where appropriate). – Bergi Apr 19 '16 at 22:50

0 Answers0