One Pager Cheat Sheet
- We will learn about
functionsand their usage in programs, focusing on function parameters, return and call statements. - Functions provide a
reusableblock of code that follows a certain structure, making it easier to organize and reuse code in a program. - By using built-in functions or defining user-defined functions, programmers can create code that allows them to easily perform specific tasks in their program.
- In JavaScript,
functionsare declared using thefunctionkeyword, followed by the function name andparenthesis, with thebody of the functiondenoted using curly braces. - We
invokedafunctionbyspecifyingits name andenclosingit withparenthesis, executing all the statements inside it. - It is not possible to
call a functionbefore it isdefinedorimplemented. - Functions can take in external information through function parameters, which are specified inside the parenthesis after the function name and separated by commas.
- The number of parameters for a function is completely up to the programmer, as they serve as
placeholdersto pass invalueswhen thefunction is called. - A function can
returnavalueto its caller, as seen in the code block with thesum(a, b, c)function, which is then stored in theresultvariable and printed to show the calculated sum. - The variable
resultprintsundefined, as the functiondivdoes not have areturnstatement and therefore does not return a value. - The code prints "a is greater than b" to the console and returns 4 as the result, producing a console output of 'a is greater than b', 4.
- You can
reuseand betterorganizeyour code by using functions, however don't forget to call them when using them in your program.

