Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

three ways of writing a function in javascript

//Three ways of writing a function in javascript
//1 Function declaration
function add(a, b) {		
	console.log(a + b);
}
// Calling it
add(2, 3);

//2 Function Expression
const add = function(a, b) {
	console.log(a+b);
}
// Calling it
add(2, 3);

//3 Arrow function (for Single line of code)
let add = (a, b) => a + b; //inbuilt return
console.log(add(3, 2));
 
PREVIOUS NEXT
Tagged: #ways #writing #function #javascript
ADD COMMENT
Topic
Name
6+3 =