
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Passing empty parameter to a method in JavaScript
Following is the code passing empty parameter to a method in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: blueviolet; } </style> </head> <body> <h1>Passing empty parameter to a method</h1> <div class="result"></div> <button class="Btn">Click here</button> <h3>Click on the above button to call multiply function and pass empty parameters to it</h3> <script> let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); function multiply(a = 2, b = 4) { return a * b; } BtnEle.addEventListener("click", () => { resEle.innerHTML = "The multiplication of numbers = " + multiply(); }); </script> </body> </html>
Output
On clicking the ‘Click here’ button −
- Related Articles
- Parameter Passing Techniques in C/C++
- Passing Multiple ids to single parameter in MySQL?
- What is the syntax for passing Scanner object as a parameter in a method using java?
- Passing parameter with parenthesis via URL in SAP Open document
- Passing to method geticon in SAPUI5
- Passing array to method in Java
- Set tuple as a method parameter in C#
- How to add a parameter to the URL in JavaScript?
- How to pass a jQuery event as a parameter in a method?
- How to pass a lambda expression as a method parameter in Java?
- How to define rest parameter for a function in JavaScript?
- Pass long parameter to an overloaded method in Java
- Passing a function as a callback in JavaScript
- How to pass an object as a parameter in JavaScript function?
- How to test if a parameter is provided to a function in JavaScript?

Advertisements