JavaScript Functions: The One Skill You’ll Use Forever.


💡 Why Functions Matter More Than You Think
When I started coding, everything felt scattered.
I had code running everywhere. Nothing felt reusable. It was like copy pasting the same logic 10 times.
Then I learned about functions, and suddenly my code felt like a real program.
🧠 What Is a Function?
A function is a reusable block of code that performs a specific task.
You give it a name, pass in inputs, and get back outputs.
🚀 How to Write Your First Function
jsCopyEditfunction greet(name) {
return "Hello, " + name + "!";
}
console.log(greet("Raj")); // Output: Hello, Raj!
📌 greet
is the name
📌 name
is a parameter (input)
📌 return
gives the result back
🔄 Why Functions Are Powerful
💬 Clean: One place to manage logic
🛠️ Reusable: Call it anytime, anywhere
📦 Modular: Break big tasks into small pieces
✅ Testable: Easier to debug and improve
🧪 Practice These Basics Today
A function that adds two numbers
A function that checks if a user is logged in
A function that loops through items and prints them
A function that returns a formatted string (like a resume card)
⚙️ Advanced Tips
- Use default parameters
jsCopyEditfunction greet(name = "Developer") {
return "Hello, " + name;
}
- Use arrow functions for shorter syntax
jsCopyEditconst greet = (name) => "Hi " + name;
- Use functions inside objects
jsCopyEditconst user = {
name: "Raj",
greet() {
return "Hello, " + this.name;
}
};
🧘♂️ Final Thought
The more functions you write, the better you think like a developer.
It’s not just code.
It’s how you structure ideas.
Subscribe to my newsletter
Read articles from Rajesh Kumar Behera directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
