w3soft.org by unix-world
0.00
Javascript Arrow Functions
How to define arrow functions in ES6 javascript
programming language: javascript ES6 or later
operating system: any
Updated: 2022-10-22
Method definition: ES6, arrow syntax
// arrow function
// this is a sample of ES6 arrow function
const myFunc = (param1, param2) => {
let a = param1;
const b = param2;
console.log(a, b);
return;
};
Method definition: ES6, standard syntax
// standard function
// this is a sample of ES6 standard function
const myFunc = function(param1, param2) {
let a = param1;
const b = param2;
console.log(a, b);
return;
};
Method definition: ES5 equivalent syntax of above samples
// classic function, ES5
// this is the ES5 equivalent for the above ES6 method
function myFunc(param1, param2) {
var a = param1;
var b = param2;
console.log(a, b);
return;
}