Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Function parameters in javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 170
    Comment on it

    We know that in JavaScript functions have parameters

    function(parameter1, parameter2, parameter3) {
        code to be executed
    } // here function is the name of the function
    

    Rules for the parameters

    • We do not specify data types for parameters in JavaScript function definitions.
    • We do not perform type checking on the passed arguments in the JavaScript functions.
    • We do not check the number of arguments received in the JavaScript functions.


    Parameter Defaults If we call a function with missing arguments (less than declared in the code), the missing values are set to: undefined Consistently this is acceptable, but sometimes it is better to assign a default value to the parameter: Example

    function Function(a, b) {
        if (b=== undefined) {
              b= 0;
        }
    }
    

    In this we are setting a default value to a function parameter that is zero.

    If a function is called with many arguments (more than declared), these arguments can be reached using the arguments object.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: