This content originally appeared on DEV Community and was authored by Buddhadeb Chhetri
Functions:-Functions in JavaScript provide organized, reusable code to perform a set of actions. Functions simplify the coding
process, prevent redundant logic, and make code easier to follow.
1.Named Function
function myfunction(){
console.log('Budddhadeb Chhetri');
}
myFunction(); //Prints: Buddhadeb Chhetri
2.Named Function with arguments
function myFunction(parameter){
console.log('parameter');
}
myFunction(10); //Prints:10
3.Anonymous function
const myFunction =function(){
console.log('Buddhadeb Chhetri');
}
myFunction(); //Prints: Buddhadeb Chhetri
4.Anonymous function with arguments
const myFunction = function(parameter){
console.log (parameter);
}
myFunction(10); //Prints: 10
5.Arrow function with no argument
const myFunction = ()=>{
console.log ('Buddhadeb');
}
myFunction(); //Prints: Buddhadeb
6.Arrow function with a single argument
const myFunction = parametrt()=>{
console.log (parameter);
}
myFunction(20); //Prints: 20
7.Arrow function with a two arguments
const mysum = (param1,param2)=>{
console.log (param1+param2);
}
myFunction(2,5); //Prints: 7
8.Concise arrow funtion with arguments
const mySum = (a,b)=>a+b;
console.log (2,5); //Prints: 7
This content originally appeared on DEV Community and was authored by Buddhadeb Chhetri
Buddhadeb Chhetri | Sciencx (2021-07-31T23:23:11+00:00) Functions in javascript. Retrieved from https://www.scien.cx/2021/07/31/functions-in-javascript-2/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.