function?A Javascript function is a block of reusable code that performs a specific task or combination of tasks. Functions are crucial building blocks of Javascript. It is good practice to declare functions at the top of the script page so as not to create execution issues later on in the page. Within functions are arguments, which act as inputs to the function. Javascript functions should follow proper naming conventions and provide a clear description of the function’s purpose.
Example: function addNumbers(a, b){//function body:code to be executed here}
invoke - or call - a function?The parenthesis are used to call a function. When using () inside a function, you are telling the function what parameters it can accept as inputs. These inputs are defined prior to the function in the script. They also are used to define where the function’s code begins and ends. Furthermore, they can be left blank inside if the function doesn’t require any inputs. They are essentially the gatekeeper that tells the function when it can execute.
Example: function addNumbers(a, b) {return a + b;}