Skip to main content

Command Palette

Search for a command to run...

Day 9: Function Parameters & Return Values in JavaScript

What Are Parameters?

Published
•2 min read•View as Markdown
Day 9: Function Parameters & Return Values in JavaScript
G

About Me Tech enthusiast and developing web developer with a growing passion for blockchain technology. My journey spans 3 years of HTML/CSS crafting, 2 years of JavaScript exploration, and recent ventures into React, Node.js, and the blockchain space. Currently at the beginning of my blockchain journey while building a solid foundation in web development technologies. Fascinated by the potential of decentralized systems and eager to contribute to this evolving ecosystem. Technical Background I bring a diverse technical toolkit that includes: Strong foundation in web fundamentals (HTML/CSS: 3 years) Dynamic front-end development with JavaScript (2 years) and React (1 year) Modern UI implementation using Tailwind CSS and Bootstrap (7 months) Server-side programming with Node.js (1 year) and Python (2-3 years) Early-stage blockchain development knowledge Beginning exploration of Rust programming (4 months) Blockchain Journey While still at the beginner level in blockchain technology, I'm actively learning about distributed ledger concepts, smart contract fundamentals, and the broader implications of Web3. My interest in this space stems from a belief in the transformative potential of decentralized technologies and their ability to reshape digital interactions. Vision & Goals My development path is guided by a clear progression: mastering web development fundamentals, expanding into blockchain applications, and ultimately exploring the intersection of these technologies with artificial intelligence. I see tremendous potential in combining these domains to create innovative solutions for tomorrow's challenges. Collaboration Interests Open to connecting with fellow developers, blockchain enthusiasts, and mentors who share an interest in the convergence of web development and emerging technologies. Particularly interested in learning opportunities, knowledge exchange, and potential collaboration on projects that push the boundaries of what's possible in the decentralized space. Current Focus Deepening my understanding of React and Node.js ecosystems while simultaneously building knowledge in blockchain fundamentals and smart contract development. Committed to continuous learning and practical application of new skills.

Parameters are variables listed inside the parentheses of a function definition. They act as placeholders for values you pass into the function.

Think of parameters like the delivery address for a package — the function needs to know where to send or use the data.

Example:

javascriptCopyEditfunction greet(name) {
  console.log(`Hello, ${name}!`);
}

greet("God'sgift");  // Output: Hello, God'sgift!
greet("Samuel");     // Output: Hello, Samuel!

Here, name is a parameter and "God'sgift" or "Samuel" are arguments (the actual values you pass).


Multiple Parameters

A function can have more than one parameter, separated by commas.

Example:

javascriptCopyEditfunction add(a, b) {
  console.log(a + b);
}

add(3, 4); // Output: 7
add(10, 5); // Output: 15

Return Values

So far, we’ve used console.log() to display results, but sometimes you want a function to give back a value you can use later.
This is where the return statement comes in.

Example:

javascriptCopyEditfunction multiply(a, b) {
  return a * b;
}

let result = multiply(5, 6);
console.log(result); // Output: 30

The return statement sends the value back to the part of the code that called the function.


Important Notes on return

  • return ends the function immediately — no code after it will run.

  • If no return is given, the function returns undefined by default.

Example:

javascriptCopyEditfunction test() {
  return "Done!";
  console.log("This will never run");
}

console.log(test()); // Output: Done!

Why Use Parameters & Returns?

They make functions reusable, dynamic, and powerful.
Instead of hardcoding values, you can pass any data you want into the same function.


Summary

  • Parameters are placeholders for function input.

  • Arguments are the actual values passed.

  • return sends a value back from the function.

  • Functions without return give undefined.


📝 Practice Questions

Easy

Write a function square that takes a number as a parameter and returns its square.


Intermediate

Create a function calculateArea that takes length and width as parameters and returns the area of a rectangle.


Hard

Write a function isEven that takes a number and returns true if it’s even, and false if it’s odd. Then use this function to log all even numbers from 1 to 20.


💡 Tomorrow (Day 10), we’ll explore Default Parameters & Arrow Functions to make your code even more flexible.

#CodeWithGift #30DaysOfJavaScript #JavaScriptSeries

More from this blog

C

CodeWithGift

31 posts

Learn more about software engineering, computer science and programming by engaging with useful and rich contents.