
- 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
How to set a default parameter value for a JavaScript function?
This came to handle function parameters with ease. You can easily set default parameters to allow initialization of formal parameters with default values. This is possible only if no value or undefined is passed. Let’s see an example
<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
- How to set default parameter values to a function in Python?
- How to define rest parameter for a function in JavaScript?
- Set a default value for the argument to cover undefined errors while calling a function in JavaScript
- How to use a function for default value in MySQL?
- Set a default value for a ttk Combobox in Tkinter?
- Setting a default variable value to undefined in a function - JavaScript?
- Does Java support default parameter values for a method?
- Is having the first JavaScript parameter with default value possible?
- How do I set the default value for a column in MySQL?
- How to set a default string value on a Tkinter Spinbox?
- How to set default value for empty row in MySQL?
- PHP – How to set or get the default scale parameter for all bc math functions using bcscale() function?
- How to set default text for a Tkinter Entry widget?
- How to set MySQL default value NONE?
- How to test if a parameter is provided to a function in JavaScript?
Advertisements