Callback Functions

Video

JavaScript Notes

JavaScript
    // Built-in callback functions
    // setTimeout, Arr.forEach, geolocation.getCurrentPosition
    // make your own callback functions
    
    setTimeout(hello, 2000, 'Bob'); // example of built in callback function
    
    let names = ['Inga', 'Tom', 'Mattias', 'Carlos'];
    names.forEach(hello); // wants to know what call back function to run for each of the names in the array
     
    navigator.geolocation.getCurrentPosition(gotPosition, positionError, { } ); //takes two callback functions
    
    function gotPosition (p){
    }
    
    function positionError(err){
    }
    
    // making your own callback function ************************* 
    function doThing( ) {
        let x = 7;
        //do lots of other things
        //…
        let name = 'Steve';
        other (name);
    }
    
    function hello (nm) {
        console.log('hello', nm);
    }
    
    doThing(hello);
    //**********************************************************