01 April 23
Frontend developmentin Javascript?
Function constructors and function declarations are two different ways of creating functions in Javascript.
A function constructor is a function that is used to create a new object. It is written with the keyword new
followed by the name of the constructor function. The constructor function can take arguments, which are passed to the constructor function and used to set properties on the new object.
For example, the following code creates a new object using the Person
constructor function:
var person = new Person('John', 'Smith');
The Person
constructor function takes two arguments, name
and surname
, which are used to set the properties name
and surname
on the new object.
A function declaration is a statement that declares a function. It is written with the keyword function
followed by the name of the function, and then a set of parentheses containing the parameters of the function.
For example, the following code declares a function called sayHello
:
function sayHello(name) { console.log('Hello ' + name); }
The sayHello
function takes one argument, name
, which is used to print a greeting to the console.
Function constructors and function declarations are two different ways of creating functions in Javascript. Function constructors are used to create new objects, while function declarations are used to declare functions.
Frontend development