How To Create JavaScript Function
Use Keyword "function" to create function with parameter or parameter less.
see the example as below.
e.g.:- 1 - Parameter Less Function
function sum(){
let a =5;
let b=10;
let c=a+b;
console.log(c);
}
e.g.:- 2 - Parameter Function
function sum(a,b){
let c=a+b;
console.log(c);
}
e.g :- 3 - Function As Expression
var sum = function(a,b){
let c= a+b;
return c;
}
let output =sum(5,10);
console.log(output );
e.g :- 4 - Arrow Function
let sum = (a,b) => a+b;
let output =sum(5,10);
console.log(output);
No comments:
Post a Comment