- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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