Global Business Hours LIVE
🇺🇸USA:EDT
🇬🇧UK:BST
🇨🇦Canada:EDT
🇦🇺Australia:AEDT
BizAIProBizAIPro
Beginner · 20 min suggested practice · Reviewed 2026-10-31

Turn Values into Results with Functions

Name values, pass arguments and return a predictable result.

By BizAIPro Learning · Prerequisites: Basic computer use. HTML helps but is not required for the console exercises.

What you will learn

  • Use const for a binding
  • Distinguish a parameter from an argument
  • Return a computed value

Values have types

A number such as 12 can participate in arithmetic. A string such as "12" is text. The + operator can add numbers or concatenate text, so understand your input types before computing. A form input usually gives you a string even when its characters look numeric.

Name a value

const creates a binding that cannot be reassigned. The name helps communicate the role of a value. Prefer unit-aware names such as unitPrice and quantity instead of short unexplained letters in application code. A useful name reduces how much context a reader must remember.

A function describes a transformation

A parameter is the local name in the function definition. An argument is the value supplied by a caller. return sends a value back to that caller. console.log prints a diagnostic message; it is not a substitute for returning a value needed by another computation.

Trace the example

The function receives 12 and 3, multiplies them and returns 36. The caller stores that result in total. The final line prints total. Change one argument, predict the new result and run the isolated JavaScript console. Practice explaining each step before adding more code.

Use it in a business tool

A pricing function should receive its inputs explicitly instead of reading arbitrary global state. This makes examples easier to test. Later lessons will add validation; this introductory function assumes appropriate numeric inputs. A successful calculation for one input does not establish correctness for all inputs.

Read the example

function lineTotal(unitPrice, quantity) {
  return unitPrice * quantity;
}
const total = lineTotal(12, 3);
console.log(total);

Line-by-line explanation

  1. unitPrice and quantity are parameters.
  2. return sends the product to the caller.
  3. lineTotal(12, 3) supplies two arguments.
  4. console.log displays the result.

Expected output

36

Common mistakes to avoid

  • Returning text when a number is required
  • Confusing printed output with a return value
  • Using unvalidated form strings as numbers
YOUR PRACTICE SPACE

Make a change. See what happens.

HTML/CSS renders in a script-free preview. JavaScript runs in a separate, time-limited console worker with network access blocked. DOM scripting and package imports are not supported. Browser memory limits still depend on your device.

Console output

Run your code to see output.
Easy · SERVER-CHECKED PRACTICE

Add two numeric values

Complete the function body by returning a + b. The assessment accepts a single return expression with arithmetic, comparisons, parentheses and conditional expressions. No loops, calls or external state.

function solution(a, b) { /* your return expression */ }
KNOWLEDGE CHECK · PASSING SCORE 100%

What does return do inside this function?

Choose one answer

Summary & next step

  • Can you now use const for a binding?
  • Can you now distinguish a parameter from an argument?
  • Can you now return a computed value?

Complete the exercise and pass the knowledge check to complete this lesson. Guest progress stays on this browser and does not sync across devices.

Related BizAIPro tools

Learn for free. Practice for real. Build your future.Search lessons