Declare and call named functions
Quick answer
A function declaration names reusable behavior. Calling the name with parentheses executes its body; merely declaring it does not run the body.
How it works
function name(parameter) { return expression; } defines a callable value. A declaration at the top level of a function body is initialized before its ordinary statements execute. Each call receives its own parameter bindings.
function double(n) { return n * 2; }console.log(double(6));Expected output in Node.js:
12The parameter receives 6 and return supplies 12.
console.log(total(4, 3));function total(a, b) { return a + b; }console.log(total(1, 9));Expected output in Node.js:
710This declaration is available before its textual position; two calls use different arguments.
Common mistakes
Do not confuse double (function value) with double(6) (result). Avoid relying on block-level declaration quirks in legacy sloppy scripts.
Practice
Write a named function returning the perimeter of a square; call it for 0 and 8.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Declare and call named functions — Knowledge Check
Apply the taught concept and reason about the result.
What does declaring a function without calling it do?
Which expression calls a function named calculate?
What does function square(n){return n*n;} followed by square(4) produce?
Can an ordinary top-level function declaration be called before its textual declaration in a function body?
Which part of a named function provides its result to the caller?