FUNCTION: It's reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code.
They can take inputs, perform actions, and return outputs.
UNDERSTANDING FUNCTIONS:
In functions, parameters are placeholders defined in the function, while arguments are the actual values you pass when calling the function.
PARAMETER: name (placeholder inside the function).
ARUGUMENT: "Vinoth" (real value given at call time).
EXAMPLE:
function greed(name) { // 'name' is a parameter
console.log("Hello " + name);
}
greedy("Vinoth"); // "Vinoth" is an argument
DEFAULT PARAMETER:
- Default parameters are used when no argument is provided during the function call.
- If no value is passed, the function automatically uses the default value.
EXAMPLE:
function greedy(name = "Guest") {
console.log("Hello, " + name);
}
greedy();
greedy("Kumar");
RETURN STATEMENT:
- The return statement is used to send a result back from a function.
- When return executes, the function stops running at that point.
- The returned value can be stored in a variable or used directly.
EXAMPLE:
function add(a, b) {
return a + b; // returns the sum
}
let result = add(50, 25);
console.log(result);
TYPES OF FUNCTIONS:


Top comments (0)