Functions Intro

Learn to Code Today!

Learn 10x faster: coding, no-code and data skills. Join millions of users mastering new tech skills and accelerating their career with Enki.
Get started

This is part of “An intro to Coding” series of posts, with content from the Enki app. If you stumbled upon this, you can start from the beginning.

Functions allow us to group commands and create new ones.

Treating a function as a command means to give it some data and ask it to produce a result.

This is commonly called *running* the function.

The terms calling, executing and invoking the function are also used. All of them mean the same thing.

As an example, imagine that you had a function called multiplyTwoNumbers.

Then you run it, you would give it the numbers 5 and 3 and it would return 15 to you as the result.

We can think of a function as divide into 3 parts.

  • input: the data given to the function
  • body: the commands (instructions) performed within the function
  • output: the result sent out of a function

💡 The inputs to a function are also called arguments.

💡 The outputing of a result from a function is also called returning a result.

Here's how you can write the multiplyTwoNumbers function using our own made-up¹ language:

To call this function we write its name, followed by a pair of ().

💡 If you take a closer look, the multiply within multiplyTwoNumbers is another function! Functions can call other functions.

In the above code, the output of multiply is saved into a variable called result and then that variable is passed out as the output of multiplyTwoNumbers.

About Enki

  • Fully personalized online up-skilling
  • Unlimited AI coaching
  • Designed by Silicon Valley experts

More articles

Meet your AI-enabled coach

Professional athletes have a coach for every aspect of their performance. Why can’t you for your work? Enki’s AI-powered coaching on-demand - combined with state of the art, structured learning content - makes this a reality.
1
1:1 AI Coaching
How do I remove duplicate emails?
Convert the list to a set and back to a list. Sets automatically remove duplicates.
2
Personalized Exercises
3
Interactive practice

Unlock full access to all skills on Enki with a 7-day free trial

Get started