PREFACE
This did not help:
This did not help:
https://www.w3schools.com/js/js_functions.asp
This did not help: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions
Please do not ask/tell me to search the forum, I did. I also searched Google. I looked at every piece of documentation I could find and for (about three years) have not been able to understand this, (I'm sure) rather simple concept.
QUESTION
I understand the basic usage of function parameters such as this:
function myFunction(x) {
var result = x * 2;
console.log(result)
}
myFunction(4);
I have always understood that usage. The usage I do NOT understand is this:
$("a").click(function(event){
event.preventDefault();
});
The variable seemingly comes out of nowhere. I understand that the variable is essentially declared/defined when you use it as a parameter, but what exactly is going on in that function? I know what the end result is, but how is it achieve by using "event". What is event?? What is its value??
Everything I have read on the web only ever explains the first usage of parameters, which is easy enough. Any help on the second usage, which I do understand they are actually being used the same way, would be greatly appreciated!
$("a").click(myFunction)then the event would be namedxinsidemyFunction.eventparameter is this: api.jquery.com/Types/#Event as noted in the jquery click method docs: api.jquery.com/clickclickmethod. When your function gets called, thateventobject is created by jquery and is passed into your method as the first parameter. That parameter within your method could be named anything, basically whatever the first parameter of your function is, that will be theeventobject passed in from the jquery event occurrence. It only lives within the scope of your function, but could be assigned to a variable at a different scope if you'd like.