Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 1.37 KB

File metadata and controls

21 lines (18 loc) · 1.37 KB

JavaScript Functions.

A JavaScript function is a block of code designed to perform a particular task.

JavaScript Function Syntax:

A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses (). The code to be executed, by the function, is placed inside curly brackets_{}_. Function parameters are listed inside the parentheses () in the function definition.Function arguments are the values received by the function when it is invoked.Inside the function, the arguments (the parameters) behave as local variables.

The code inside the function will execute when "something" invokes (calls) the function:

  1. When an event occurs (when a user clicks a button).
  2. When it is invoked (called) from JavaScript code.
  3. Automatically (self invoked).

Function Return:

When JavaScript reaches a return statement, the function will stop executing.

Features functions:

  1. You can reuse code: Define the code once, and use it many times.
  2. You can use the same code many times with different arguments, to produce different results.
  3. A well-named function communicates clearly it's purpose.
  4. Functions help us avoid repeated code.

To learne more about the functions visit FUNCTIONS, and SKIM OF FUNCTIONS .