Passing Data into Functions
We can pass data into functions using parameters:
function funcName(parameter1, parameter2, ...) {
// your code here…
}
A parameter acts like a local variable inside the function. However, it takes up the value of the corresponding argument that is passed into the function at the function call.
12345678function sum(a, b) { console.log(a + b); } sum(1, 2); // Output: 3 sum(5, 10); // Output: 15 sum(20, 30); // Output: 50 sum(33, 37); // Output: 70
- An argument is the actual value passed into a function when calling it:
- Example: In
sum(1, 2), the values1and2are arguments;
- Example: In
- A parameter is a placeholder inside the function definition that receives the argument’s value:
- Example: In
function sum(a, b),aandbare parameters.
- Example: In
A function in which other functions are called is known as a compound function. A compound function combines smaller functions to accomplish a larger task.
1. How many parameters does this function have?
2. What will be the output of this code?
3. Which of the following is true?
Danke für Ihr Feedback!
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Großartig!
Completion Rate verbessert auf 1.33
Passing Data into Functions
Swipe um das Menü anzuzeigen
We can pass data into functions using parameters:
function funcName(parameter1, parameter2, ...) {
// your code here…
}
A parameter acts like a local variable inside the function. However, it takes up the value of the corresponding argument that is passed into the function at the function call.
12345678function sum(a, b) { console.log(a + b); } sum(1, 2); // Output: 3 sum(5, 10); // Output: 15 sum(20, 30); // Output: 50 sum(33, 37); // Output: 70
- An argument is the actual value passed into a function when calling it:
- Example: In
sum(1, 2), the values1and2are arguments;
- Example: In
- A parameter is a placeholder inside the function definition that receives the argument’s value:
- Example: In
function sum(a, b),aandbare parameters.
- Example: In
A function in which other functions are called is known as a compound function. A compound function combines smaller functions to accomplish a larger task.
1. How many parameters does this function have?
2. What will be the output of this code?
3. Which of the following is true?
Danke für Ihr Feedback!