Key Concepts:
- Function name: Identifies the block of code to be executed.
- Parentheses: Enclose function arguments.
- Arguments: Values or data passed to the function for processing.
Steps to Call a Function:
- Identify the function name.
- Write parentheses after the function name.
- Pass any required arguments inside the parentheses, separated by commas.
- End the statement with a semicolon (;).
Example in JavaScript:
function myFunction(name, age) {
console.log("Hello, my name is " + name + " and I am " + age + " years old.");
}
myFunction("John", 30); // Execute the function with arguments
Calling Functions Made Simple:
You can think of calling a function like giving it a job to do.
- Find the function's name: It's like the name of your boss.
- Write parentheses next to the name: Imagine them as your boss's office door.
- Put any information inside the parentheses: These are the specific details your boss needs to do the job.
- End with a semicolon (;): It's like saying, "Okay, boss, start working!"
Example:
function sayHello(name) {
console.log("Hello, " + name + "!");
}
sayHello("Maria"); // Send the name "Maria" to the function