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 Reply

Your email address will not be published. Required fields are marked *