javascript function default value for parameter


function square(a){

    if( typeof a == 'undefined' ) { // set value by default

        a = 10;

    }

    return a*a;

}



square(); // will return '100'

Leave a Comment