Page 195 - CITS - Computer Software Application -TT
P. 195

COMPUTER SOFTWARE APPLICATION - CITS











           Note: A function name must start with a letter or an underscore. Function names are NOT case-sensitive.
           Tip: Give the function a name that reflects what the function does!
           Call a Function
           To call the function, just write its name followed by parentheses ():
           Example:





















           In our example, we create a function named myMessage().
           The opening curly brace { indicates the beginning of the function code, and the closing curly brace } indicates the
           end of the function.
           The function outputs “Hello world!”.
           Function Name and Scope:
           Function  names  are  case-insensitive.  However,  it’s  good  practice  to  follow  a  consistent  naming  convention.
           Functions have their own scope, meaning variables inside a function are not accessible outside of it.
           Function Parameters:
           Parameters  allow  us  to  pass  data  into  functions.  They  are  defined  within  the  parentheses  during  function
           declaration.
           Example:









           Function Body:
           The function body contains the code to be executed when the function is called.
           Parameters and Return Values
           Functions can accept parameters and return values, making them versatile and adaptable to various scenarios.
           There are three types of parameters:
           •   Required Parameters: Must be passed during the function call.
           •   Default Parameters: Have default values and can be omitted.
           •   Variable-length Parameter Lists: Allow an arbitrary number of arguments.
           Example:





                                                           182

                             CITS : IT&ITES - Computer  Software Application - Lesson 47 - 62
   190   191   192   193   194   195   196   197   198   199   200