Please enable JavaScript to use CodeHS

CodeHS Glossary


Call a Function JavaScript

Calling a function actually gives the command, so the computer will run the code for that function.

As opposed to defining a function, calling a function actually runs code. In order to call a function, you must define it first, so the computer knows what to do.

You can also refer to calling a function as “giving a function,” “giving a command,”or “running a command.”


Example in Karel

function start() {
    move();
    turnRight(); // Calls the function
}

// Defines the function
function turnRight() {
    turnLeft();
    turnLeft();
    turnLeft();
}

When you just define a function, it does not run any of the commands inside it, so you also need to call the function where you want the commands to actually run.