

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are optional arguments in JavaScript Functions?
To declare optional function parameters in JavaScript, use the “default” arguments.
Example
You can try to run the following code to declare optional parameters −
<html> <body> <script> // default is set to 1 function inc(val1, inc = 1) { return val1 + inc; } document.write(inc(10,10)); document.write("<br>"); document.write(inc(10)); </script> </body> </html>
- Related Questions & Answers
- What are functions in JavaScript?
- What are JavaScript Math Functions?
- What are JavaScript Nested Functions?
- What are JavaScript Factory Functions?
- What are generator functions in JavaScript?
- What are immediate functions in JavaScript?
- What are callback functions in JavaScript?
- What are Partial functions in JavaScript?
- How to use named arguments in JavaScript functions?
- How to pass arguments to anonymous functions in JavaScript?
- What are Rest parameters in JavaScript functions?
- How to use Spread Syntax with arguments in JavaScript functions?
- What are Self-Invoking Anonymous Functions in JavaScript?
- What are default arguments in python?
- What are variable arguments in java?
Advertisements