In this short article we will cover and learn how to use it in our day to day JavaScript programming. This article assumes you have some familiarity with coding in the JavaScript ecosystem. Function Defaults Function Defaults Function parameters are weird in JavaScript, when you call a function in or without arguments, you get syntax errors. But when calling a function without providing parameters in JavaScript, your code just runs. This can result to your functions being called with incomplete inputs and that could introduce some bugs. You can counter this problem with . Java C# defensive programming You can add some additional or validations if a function’s parameters have the correct values. But having a lot of if statements for most of your functions could result to messy code. A better way for this is to use the feature where you can have function defaults. As the example code shows, you can simplify the validation of your function parameters by setting default values. if statements ES6 { x + y; } .log(sum()); ( ) function sum x= , y= 0 0 return console // expected output: 0 Using Another Parameter as the Default You can also use function defaults one step further by using another parameter as the default. In the code example below, the function just squares the first parameter if the second one isn’t provided. product() { x * y; } .log(product( )); ( ) function product x, y=x return console 3 // expected output: 9 End That is all. We used simple examples but we learned how to set sane default values for the parameters in our JavaScript functions, preventing unexpected behavior while keeping the code clean. Originally published at https://micogongob.com/modern-javascript-function-defaults