Heart of Javascript: Javascript Functions (Part 01)

Heart of Javascript: Javascript Functions (Part 01)

Functions In Javascript

  1. Introduction to Function
  2. Function Declaration in JavaScript
  3. Return Keyword in JavaScript
  4. Passing Parameters in a JavaScript Function
  5. Higher Order Objects in JavaScript
  6. Function Expression in JavaScript
  7. Arrow Functions in JavaScript
  8. Anonymous Functions in JavaScript
  1. Introduction to Functions : Functions are used because of the following reasons –
    a) To improve the readability of code.
    b) Improves the reusability of the code, the same function can be used in any program rather than writing the same code from scratch.
    c) Debugging of the code would be easier if you use functions, as errors are easy to be traced.
    d) Reduces function calls to replace the size of the code, and duplicate set of statements.


  1. Function Declaration in JavaScript :

Capturezzzz.JPG

Functions are not invoked unless they are called hence we need to call it

  1. Return keyword

The moment inside our function block we hit the return statement, function execution is stopped and the value is returned to the caller

Captursasase.JPG

If the return keyword is not written and the entire function body statements are executed then automatically a return statement is put by the Javascript engine.

  1. Passing Parameters in Javascript Functions

While Passing Parameters in a JavaScript function we do not pass it as let or var, because it is assumed that the scope of the value passed is till the function execution is complete

Casasasasasapture.JPG

  1. Higher Order Objects Functions in JavaScript are treated like objects hence operations can be performed on Object just like other objects

Captuasddadadsdsdasdre.JPG

  1. Function Expression When we assign a function to a variable it Is called a function expression.

Captuasddadadsdsdasdre.JPG

  1. Arrow Function

arrow_function..JPG

  1. Anonymous Function Functions without a name are called an anonymous function

Capture_anonynous.JPG