optional parameters in an async function

How can I have optional parameters in an async function with callbacks?

For example this is my call:

func1(param1, param2, param3, param4, param5, param6, function(err, data) {
  .
  .
  .
}

and here I would like to have param5 and param6 optional;

        module.exports.func1= function(param1, param2, param3, param4, param5, param6, callback) {
      .
      .
      .
  }

I guess the simple approach is to see whether they are undefined or not , if they are, we set the default value; is that the only way?

Thanks

Use the "arguments" attribute inside the function to know the length of it (how many arguments you have). The last is the callback function, the others are param1, param2, etc...

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments

UPDATE: I made a fiffle with example (can improve the logic) http://jsfiddle.net/4gda1sdw/

function func1() {
    var arg_lenght = Array.prototype.slice.call(arguments, 0).length -1;
    var args = Array.prototype.slice.call(arguments, 0, arg_lenght);
    var cb = Array.prototype.slice.call(arguments, 0)[arg_lenght];
    alert(args);
    alert(cb);
}

func1(1, 2, 3, 4, function() {});

Basically, you have to check if they're undefined. A nice way of handling this is with a pattern kind of like this:

function func1(a, b, c, d, e, callback) {
    a = a || 'use';
    b = b || 'short';
    c = c || 'circuiting';
    d = d || 'for';
    e = e || 'defaults';
    callback = callback || function(){};
    ...
}

Because undefined evaluates as "falsy" it will take the result on the right, so this automatically checks for undefined while assigning a reasonable default.

If you want to avoid inserting default parameters at all then you can make use of the arguments object.

function func1(a, b, c, d, e, callback) {
    for (var i = 0, len = arguments.length; i < len; i++) {
        if (typeof arguments[i] === 'function') {
            callback = arguments[i];
            break;
        }
    }

    // Fill in defaults here
}