General question


#1

I have a query.

  1. we used to define function like this.

var function_name=function(parameter)
{
//body part
};

do the above part is same as this: ?

function function_name(parameter)
{
//body part
};

2 as a whole is this a constructor ? or the last line symbolizes the constructor ??

function Person(name,age) {
this.name = name;
this.age = age;
}
var bob = new Person("Bob Smith", 30);

Thanks in advanvce


#2

@stetim94 can you help me with this ?


#3

there are two type of functions, function definition (also called a function declaration, or function statement):

function function_name(parameter)
{
//body part
};

and Function expressions:

var function_name=function(parameter)
{
//body part
};

you can read about it here, quit a nice read :slight_smile: There are some differences.

  1. this is the constructor:

function Person(name,age) {
this.name = name;
this.age = age;
}

You made your own constructor here, you learned about it in this lesson


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.