What does this code do? Can someone describe why the function is inside a parenthesis and also why it has a parenthesis at the end and what it is doing?
(function (innerKey) {
//doSomething
}(key));
What does this code do? Can someone describe why the function is inside a parenthesis and also why it has a parenthesis at the end and what it is doing?
(function (innerKey) {
//doSomething
}(key));
It's a self-invoking anonymous function. It will be called immediately after loading the script, and it will take the element inside the brackets key
as the function's argument.
You can read more here: What is the (function() { } )() construct in JavaScript?
You are creating the function and invoking it at the same time with the key value filling the innerkey parameter.