How to pass arguments to anonymous functions in JavaScript?

Following is the code for passing arguments to anonymous functions in JavaScript −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .result {
      font-weight: 500;
      font-size: 20px;
      color: blueviolet;
<h1>Pass arguments to anonymous functions</h1>
<div class="result"></div>
<br />
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to call an anonymous function and pass
parameters to it</h3>
   let BtnEle = document.querySelector(".Btn");
   let resEle = document.querySelector(".result");
   let add = function (a, b) {
      return a + b;
   BtnEle.addEventListener("click", (event) => {
      resEle.innerHTML = "The sum of 22 and 19 = " + add(22, 19);


On clicking the ‘CLICK HERE’ button −