Immediately Invoked Function Expressions

Video

JavaScript Notes

JavaScript
    // Immediately Invoked Function Expressions
    // Wrapping the function with parenthesis, turns it into an immediately invoked function
    // The extra set of parenthesis at the end tells it to run
    
    (function doSomething( ){
    // function declaration
     
    }) ( );
    
    var somethingElse = (function (nm) {	// this is an anonymous function
        // function expression 
        return {
            "name": nm,
            "id": 123,
            x: function ( ) {
            }
        }
    } ) ("Bob");
    
    console.log(somethingElse.name, somethingElse.id); 
    somethingElse.x( );
    
    doSomething; // like shouting out a name – does nothing
    doSomething( ); // actually runs the function and waits for a return value
    
    somethingElse; //
    somethingElse ( ); // actually runs the function and waits for a return value