I have created a JavaScript Function with a default argument remove = false but when No value is passed the remove parameter do not acquire the default "false" value instead of that it acquires a very large object, See my Function code:-
infoBtnCB.addEventListener("click", clickEventInfoBtn_CB);
function clickEventInfoBtn_CB(remove = false) {
console.log(remove);
if (remove) {
infoBtnCB.classList.remove("active-info-btn-CB");
} else {
infoBtnCB.classList.toggle("active-info-btn-CB");
}
if (infoBtnCB.innerHTML == "Info" && !remove) {
setTimeout(() => {
infoBtnCB.innerHTML =
"Lorem ipsum dolor sit, amet consectetur adipisicing elit. Cumque accusamus ipsum, quidem harum similique blanditiis, veritatis nam sapiente tenetur rerum temporibus asperiores, commodi consequatur corporis quisquam aspernatur quas laudantium eaque.m";
}, 100);
} else {
infoBtnCB.innerHTML = "Info";
}
}
OUTPUT WHEN FUNCTION IS CALLED AS : clickEventInfoBtn_CB(true)
we get remove = true;
and when,
IT IS CALLED BY EVENTLISTNER:-
we get remove = PointerEvent {isTrusted: true, pointerId: 1, width: 1, height: 1, pressure: 0, …};
remove = falsedoesn't mean that the event handler will be called with a boolean - it's always passed an event. That's how all event handler callbacks are executed.eventso that eventListner will not add its event to my remove parameter??.addEventListener("click", () => clickEventInfoBtn_CB())