Mark As Completed Discussion

One Pager Cheat Sheet

  • We will learn about functions and their usage in programs, focusing on function parameters, return and call statements.
  • Functions provide a reusable block 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, functions are declared using the function keyword, followed by the function name and parenthesis, with the body of the function denoted using curly braces.
  • We invoked a function by specifying its name and enclosing it with parenthesis, executing all the statements inside it.
  • It is not possible to call a function before it is defined or implemented.
  • 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 placeholders to pass in values when the function is called.
  • A function can return a value to its caller, as seen in the code block with the sum(a, b, c) function, which is then stored in the result variable and printed to show the calculated sum.
  • The variable result prints undefined, as the function div does not have a return statement 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 reuse and better organize your code by using functions, however don't forget to call them when using them in your program.