Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
ES6 Default Parameters in nested objects – JavaScript
Yes, you can pass default parameters in nested objects.
Following is the code −
Example
Following is the code −
function callBackFunctionDemo({ cl: { callFunctionName = "callBackFunction", values = 100 } = {} } = {}) {
console.log(callFunctionName);
console.log(values);
}
//This will print the default value. // 100
callBackFunctionDemo();
//This will print the given value. //500
callBackFunctionDemo({ cl: { values: 500 } });
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo296.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo296.js callBackFunction 100 callBackFunction 500
Advertisements
