# JS Tip of the Day: Default Function Parameters

**URL:** <https://forum.kirupa.com/t/js-tip-of-the-day-default-function-parameters/643178>\
**Category:** web dev\
**Created:** [February 18, 2020, 1:15pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-default-function-parameters/643178 "2020-02-18T13:15:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [February 18, 2020, 1:15pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-default-function-parameters/643178/1 "2020-02-18T13:15:55Z")

</div>

**Default Function Parameters**  
Version: ES2015  
Level: Beginner

Functions in JavaScript can be called with any number of arguments, whether or not they expect them. If a function parameter does not have a respective argument, it will appear in that function as `undefined`.

```auto
function logValues (a, b) {
    console.log(a);
    console.log(b);
}

logValues(1); // 1, undefined

```

If you want a parameter to have a specific value if the function is called without that respective argument, you can specify a default parameter value. To define a default parameter add an assignment expression in the parameter list of the function for that parameter. If the parameter were to have an `undefined` value, it would instead be assigned to the default parameter value.

```auto
function logValues (a, b = 2) { // b's default parameter value is 2
    console.log(a);
    console.log(b);
}

logValues(1); // 1, 2

```

More info:

- [Default Parameters on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters)
