How to set default parameters in ES6 ? Last Updated : 16 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Function parameters with default values are initialized with default values if they contain no value or are undefined. JavaScript function parameters are defined as undefined by default. However, it may be useful to set a different default value. That is where default parameters come into play. Syntax: function name(parameter=value,...parameters) { } Example 1: If we multiply two numbers in this example without passing a second parameter and without using the default parameter, the answer that this function will return is NAN(Not a Number), since if we do not pass the second parameter, the function will multiply the first number with undefined. JavaScript function multiply(a, b) { return a * b; } let num1 = multiply(5); console.log(num1); let num2 = multiply(5, 8); console.log(num2); Output: NaN 40 Example 2: If we do not pass a number as the second parameter and take the default parameter as the second parameter, it will multiply the first number with the default number, and if we pass two numbers as parameters, it will multiply the first number with the second number. JavaScript function multiply(a, b = 2) { return a * b; } let num1 = multiply(5); console.log(num1); let num2 = multiply(5, 8); console.log(num2); Output: 10 40 Example 3: Default Parameter with Constructor: we can use the default parameter concept with the constructor of a class. JavaScript class Geeks { constructor(a, b = 3) { console.log(a * b); } } let obj = new Geeks(5); let obj1 = new Geeks(5, 4); Output: 15 20 Comment More infoAdvertise with us Next Article How to set default parameters in ES6 ? D debadebaduttapanda7 Follow Improve Article Tags : JavaScript Web Technologies ES6 JavaScript-Questions Similar Reads How to set default parameter value in JavaScript functions ? In general all the JavaScript functions have a default value of undefined but we can overwrite it by specifying a particular value. This prevents breaking of the code in case of missing inputs. Let us first take a look at a problem and then we'll take a look at how default values for function parame 2 min read How to create default function parameter in PHP? The default parameter concept comes from C++ style default argument values, same as in PHP you can provide default parameters so that when a parameter is not passed to the function. Then it is still available within the function with a pre-defined value. This function also can be called optional par 1 min read How to Create Query Parameters in JavaScript ? Creating query parameters in JavaScript involves appending key-value pairs to a URL after the `?` character. This process is essential for passing data to web servers via URLs, enabling dynamic and interactive web applications through GET requests and URL manipulation. Example: Input: {'website':'ge 3 min read How to include a template with parameters in EJS ? EJS (Embedded JavaScript) is a templating language that enables dynamic content generation in HTML files using JavaScript syntax. EJS templates consist of HTML code mixed with JavaScript expressions enclosed within <% %> tags. We will discuss the following approaches to include template with p 4 min read Explain the Rest parameter in ES6 In this article, we will try to understand the details associated with the rest parameter in ES6 which includes the syntax of rest parameters, and how to use this with the help of certain examples. The rest parameter is an improved way to handle function parameters, allowing us to handle various inp 3 min read Like