Promptles
Programming Basics

Function

beginner

Definition

A reusable block of code that performs a specific task. You give it a name, and whenever you need that task done, you 'call' the function by name instead of writing the same code again. Functions can accept inputs and produce outputs.

In the wild

function greet(name) { return 'Hello, ' + name; } defines a function called 'greet'. Calling greet('Alice') runs that block and gives back 'Hello, Alice'. You can call it as many times as you want with different names.

More from Programming Basics