Knowledge Maxxing
← Back to topic library
Dev MaxxingBeginnerJavaScript60 sec

JavaScript function

A JavaScript function is a reusable block of code that can accept input values as parameters and optionally return a result.

Prerequisite: JavaScript variable

What matters

Wrapping logic in a function lets it be reused in multiple places without duplicating code, and named parameters make what the function needs explicit.

Example

A function 'add(a, b)' that returns 'a + b' can be called repeatedly with different values instead of rewriting the addition logic each time.

Common misconception

A JavaScript function does not have to explicitly return a value; without a return statement, it simply returns 'undefined' by default.

Recall question

What happens when a JavaScript function has no explicit return statement?

Keywords and related concepts

JavaScript functionparametersreturn valuejavascript variable

Related topics

JavaScript variable
Dev MaxxingBeginner
Browser event
Dev MaxxingBeginner