JAVASCRIPT Tutorial

Calling Functions

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:

  1. Identify the function name.
  2. Write parentheses after the function name.
  3. Pass any required arguments inside the parentheses, separated by commas.
  4. 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.

  1. Find the function's name: It's like the name of your boss.
  2. Write parentheses next to the name: Imagine them as your boss's office door.
  3. Put any information inside the parentheses: These are the specific details your boss needs to do the job.
  4. 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