Built UI components

Intro to Javascript Functions


What is a Function?

A function is a logical building block inside of which a set of codes are written in order to perform a specific task. Practically, functions allow writing codes in a more organized way that is also easy to debug and maintain. Functions also allow code reuse. You define function once, and call it when you need to without writing the same codes again and again.

Invoking a Function
The function declared before will be invoked when any one of the following occurs:
  • When an event occurs for example, user clicks on a button or user selects some option from the dropdown list etc.
  • When the function is called from the javascript code.
  • The function can also be invoked automatically, we already discussed that in anonymous function expression.
The () operator invokes the function.