how to call a function javascript code example

Example 1: running a function in a function javascript

function runFunction() {
  myFunction();
}

function myFunction() {
  alert("runFunction made me run");
}

runFunction();

Example 2: Functions call functions js

/*
Write a function sum that takes an array of numbers and 
returns the sum of these numbers. 
Write a function mean that takes an array of numbers and 
returns the average of these numbers. 
The mean function should use the sum function.
*/
function sum (arr) {
    let suma = 0;
    for (let i = 0; i < arr.length; i++) {
        
        let num= parseInt(arr[i]);
        suma += num;
    }
    return suma;
  }
  
  function mean (arr) {
    let average = sum(arr) /arr.length;
    
    return average;
  }

Example 3: call function javascript

// Define your function
function sayHello(msg){
	console.log("Hello, " + msg);
}

// Call it
sayHello("Norris");

// outputs:
// Hello, Norris

Example 4: how do i call a js method?

<button onclick="sayHello()">say hello</button>  <script>    'use strict';  //force the context to be undefined    function sayHello() {      console.log(this);      console.log(arguments);      console.log('hello');    }  </script>