Forbes magazine logo Ranked Best Coding Bootcamps 2023

What is Function?

Web Development Jargons Explained in 5 Different Ways

TLDR: A function can be thought of as a machine that performs a specific task. Such as make sandwich. Every time you want a sandwich to be made, you just have to turn on the machine. Or execute the function, as programmers would say.


Explain like I only speak in plain English

A function can be thought of as a machine that performs a specific task. Such as make sandwich. Every time you want a sandwich to be made, you just have to turn on the machine. Or execute the function, as programmers would say.

Functions are important in programming because it allows programmers to dissect parts of the program where the same task is carried out repeatedly.

Instead of repeating all the instructions to make a sandwich. The programmer can pack all the instructions inside a function, call it makeSandwich. And execute the function whenever a sandwich needs to be made.

Explain like I'm a total nerd

Functions can take inputs, and give outputs. You can think of the inputs as ingredients. Outputs as the end products. For a function that is to make sandwiches. You can give it inputs of bread, peanut butter, and jelly. The output would be a peanut butter jelly sandwich.

The coolest thing about functions is that they can contain and use other functions too. As an example, our makeSandwich function can use the toastBread function to toast the bread before making it into a sandwich.

Explain like I Like Examples

The following is a simple function written in JavaScript. It will add the two input numbers and return their sum.

var sum = function (a, b) {
  return a + b;
}
// sum(3, 7) will return 10

Explain like I like videos

Explain like I already know it

Functions are important as it helps keep our programs DRY (Don't Repeat Yourself). Whenever you find yourself repeating identical or similar code, you should consider abstracting it into a function.

Another neat thing about functions is that they can call themselves, these are called recursive functions. Programmers often rejoice whenever they see an elegant recursive function in use.

We are trusted by

Students and instructors from world-class organizations

Imperial College London
Carnegie Mellon University
City University of Hong Kong
Hack Reactor
Cisco Meraki
University of Oxford
Swift
Bazaarvoice
Waterloo
Uber
AtlanTech
Tumblr
Boston College
Bombardier Aerospace
University of St. Andrews
New York University
Minerva Schools at KGI
Merrill Lynch
Riot Games
JP Morgan
Morgan Stanley
Advanced Placement®
Google
KPMG
The University of Hong Kong
University of Toronto
SCMP
Moat
Zynga
Hello Toby
Deloitte
Goldman Sachs
Yahoo
HSBC
General Assembly
Tesla
McGill University
Microsoft

Join the upcoming Cohort #95

Enroll for November 4th, 2024