FUNCTIONS - JS

Declaring a new function

  1. We declare a new function by starting with the key word "function" and "()" after the name is chosen for our function.
  2. We write the body of the function between the "{ }"
  3. We return the result thanks to the key word "return"
// Declare a simple example
function WhoRunTheWorld() {
  return 'Girls';
}

//Use it
const answer = WhoRunTheWorld()
//result answer = 'Girls'

4.We can add parameters between "()"

// Declare a simple example with parameters
function add(a, b) {
  return a + b;
}
//Use it
const calcul = add(5, 6)
//result : calcul = 11

Was this article helpful?

Powered by Zendesk