function

Estimated reading time: 1 minute

what is function

Function is a block for getting a particular task

  • particular task
  • reuse

function element

  • function name
  • function keyword
  • parentheses (parameter)
  • curly brackets ({}) . where stay statement
    • return
  • calling function

ex-1

function functionName (par1,par2) {
  return par1 + par2;
}
let result = functionName(3,2);
console.log(result);
// 5

ex-2

functionName = function (var1,var2) {
  return var1 + var2;
}
let result =  functionName(3,2);
console.log(result);
// 5

es6

  • See more details in es6 tutorial in code4mk.
functionName =  (var1,var2) => {
  return var1 + var2;
}
let result =  functionName(3,2);
console.log(result);
// 5

call inside another function

function user(){
  console.log("yes you can do this")
}
//let a = 5
function employee(){
  user()
}
employee()

references

js