JavaScript Functions Explained: Input Parameters and Return Values for Beginners
Published on June 9, 2025 • 4 min read

Understanding JavaScript Functions: No Input, No Output
Let's start with the most basic type of JavaScript function — one that neither takes any input nor returns any output. Imagine you have two variables, a
and b
, assigned values 100 and 200 respectively. We want to add these and display the result. Here's how to create such a function in JavaScript:
let a = 100;
let b = 200;
function add() {
let c;
c = a + b;
console.log(c);
}
add();
- The function
add
is declared without parameters (empty parentheses). - Inside the function, we create a local variable
c
to hold the sum ofa
andb
. - We print
c
usingconsole.log()
because, without a return statement, the function does not return a value.
Note: Defining a function doesn’t execute it — you must explicitly call it using its name followed by parentheses, as shown with add();
. If you run this code without calling add()
, you will see no output.
For a deeper dive into JavaScript execution contexts and how memory is allocated in the stack during function calls, see the official Node.js documentation.
No Input but Returning Output: Using the Return Statement
What if you want your function to calculate something but instead of printing the result directly, you want to send it back to wherever the function was called? This is where return
comes in.
Consider the previous example. Modify it to return the sum rather than printing it:
function add() {
let c;
c = a + b;
return c;
}
let result = add();
console.log(result); // Outputs: 300
Here:
add()
returns the valuec
(which is 300).- The calling code captures this value in the variable
result
. - We then optionally print
result
.
This pattern — no input parameters and returns output — is common when the function's responsibility is purely to compute and give back a result.
Check out the MDN Web Docs on function return for more details.
Functions Accepting Input Without Returning Output
Now let's explore functions that take input parameters but don't return any output — instead, they perform an action such as printing the result.
Here's an example:
function add(x, y) {
let c = x + y;
console.log(c);
}
let a = 100;
let b = 200;
add(a, b);
Key points here:
add
accepts two parameters, namedx
andy
, which act as placeholders for values passed when calling the function.- When calling
add(a, b)
, values ofa
andb
are passed tox
andy
respectively. - The function adds
x
andy
and then immediately logs the result usingconsole.log
.
Avoid declaring parameters inside the function with let
or var
, e.g., let x
, which will cause errors — just use the parameter names directly.
For further reading, see the JavaScript Functions guide at W3Schools.
Functions Accepting Input and Returning Output
Finally, the most versatile function type takes input and returns an output:
function add(x, y) {
let c = x + y;
return c;
}
let a = 100;
let b = 200;
let result = add(a, b);
console.log(result); // Outputs: 300
- Just like before, the function accepts inputs
x
andy
. - It adds them and returns the sum.
- The calling code captures the returned value in
result
. - You can then use or display
result
as needed.
This pattern is fundamental to writing modular and reusable code.
Check out JavaScript function parameters and return values on MDN for a comprehensive explanation.
Conclusion
Understanding these four fundamental types of JavaScript functions will strengthen your coding foundation:
- Functions with no input and no output perform tasks internally like printing results.
- Functions with no input but returning output compute and send back results.
- Functions with input parameters perform actions based on provided data.
- Functions with input parameters that return output offer the most flexibility for reusable logic.
Start experimenting with these patterns in your own projects and observe how function execution affects memory through the stack and execution contexts. Remember, functions must be called to run, and variables declared inside functions exist only during that function's execution.
Ready to deepen your JavaScript skills? Explore more advanced function concepts like closures, callbacks, and asynchronous functions next!
If you found this guide helpful, please like, subscribe, and leave your questions or thoughts in the comments. Your feedback motivates us to create more quality content. Happy coding!
This blog post is based on content from a YouTube video. Watch it here. All rights reserved by the original creator.