javascript use function in function code example

Example 1: does a function inside a function need to be called?

function outer() { 

    // when you define it this way, the inner function will be accessible only from 
    // inside the outer function

    function inner() {
        alert("hi");
    }
    inner(); // call it
}

Example 2: javascript function call with variable

function abc() {
  alert('test');
}

var funcName = 'abc';

window[funcName]();

Example 3: 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>

Tags:

Misc Example