0

Here i have two questions regarding javascript functions

  1. When to use function declaration and when to use function expression

  2. This is an function expression

    var run = function (){ // code stuff }

This is an function declaration

function walk(){
// code stuff
}

What do we call functions written inside below object(human) is it declaration or expression?

var human = {

  think : function(){

       }

 roll : function(){

     }

 }
  • 1
    `human.think()` and `human.roll()` is a function expression – gurvinder372 Apr 13 '16 at 06:43
  • The functions inside object are called `methods` – Tushar Apr 13 '16 at 06:44
  • @gurvinder372 haha.. I too thought about the same. But he is asking the technical term to pronounce that. – Rajaprabhu Aravindasamy Apr 13 '16 at 06:45
  • 1
    Check out http://stackoverflow.com/questions/10081593/are-named-functions-or-anonymous-functions-preferred-in-javascript and http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname – Steve Apr 13 '16 at 06:45
  • @RajaprabhuAravindasamy I am not sure about a technical term that is specified for this particular scenario but `Behaviour` or `Method` (as Tushar mentioned) could be the term used for this (since this is specified inside a class/function). – gurvinder372 Apr 13 '16 at 06:52

0 Answers0