- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What is the best way to do optional function parameters in JavaScript?
To include optional function parameters in JavaScript, you can try the following,
function myFunc(a, b = 0) { // function body }
Example
You can try to run the following code to learn how to include optional function 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 Articles
- How can I declare optional function parameters in JavaScript?
- How to pass optional parameters to a function in Python?
- Can I extend a JavaScript error? What is the best way to do so?
- What is the best way to concatenate strings in JavaScript?
- What is the best way to compare two strings in JavaScript?
- What is the best way to add an event in JavaScript?
- What is the best way to initialize a JavaScript number?
- Optional Parameters in Dart Programming
- What is the best way to break from nested loops in JavaScript?
- What is the best way to initialize a JavaScript Date to midnight?
- What are default-parameters for function parameters in JavaScript?
- What is the best way of declaring multiple Variables in JavaScript?
- What are function parameters in JavaScript?
- What is the best way to convert a number to a string in JavaScript?
- What is the best way to handle a Javascript popup using Selenium Webdriver?

Advertisements