Accelerated JS Tutorial
Live Help
  • Evie's Accelerated JS Tutorial
  • Variables
  • Simple Data Types
    • Template Literals
  • Mid Level Data Types
    • Awesome Array Methods
  • Advanced Data Types
    • Map
  • Understanding Conditions
  • Understanding Functions
    • Using and Calling Functions
    • ES6 functions
    • Lambda / Anonymous Functions
    • Callbacks
    • Pure Functions and Side-Effects
    • Chaining Functions
  • Understanding Modules
  • Understanding Classes
  • Understanding Promises
Powered by GitBook
On this page

Understanding Functions

A function is lines of code that you call from other places in your code to execute certain things. They're used far and wide, mostly when there's code you want to execute many times.

A function is lines of code that you call from other places in your code to execute certain things. They're used far and wide, mostly when there's code you want to execute many times.

A function takes the following shape, basically:

function myFunc(arguments) {
  // function code
}

A function may return something, or not. Here's an example of a function that returns a value:

function add(a, b) {
  return a + b;
}

And here's one that does not return a value, but still executes something:

function log(type, message) {
  console.log(`[${type}] ${message}`);
}

PreviousUnderstanding ConditionsNextUsing and Calling Functions

Last updated 3 years ago