Professional Documents
Culture Documents
Java Script Function Types
Java Script Function Types
Java Script Function Types
function functionName(parameters) {
// code to be executed
}
EX :
function myFunction(a, b) {
return a * b;
}
Function Expressions :
Const X = myFunction(a, b) {
return a * b;
}
Calling above function
let z = x(4, 3);
-----------------------------------------------------------------------
Constructor Function :
Functions can also be defined with a built-in JavaScript function
constructor called Function()
Ex :
(function () {
let x = "Hello!!";
})();
The function above is an anonymous self-invoking function (function
without name).
Arrow Functions :
var x = function(x, y) {
return x * y;
}
Arrow function :
const x = (x, y) => { return x * y };
Arrow functions are not hoisted. They must be defined before they are
used.
-----------------------------------------------------------------------
Function Parameters :
-----------------------------------------------------------------------
const myObject = {
firstName:"John",
lastName: "Doe",
fullName: function () {
return this.firstName + " " + this.lastName;
}
}
myObject.fullName();
Invoking Function with Function Constructor :
EX :