In this video, we’ll explore a JavaScript function with three parameters and how to use them effectively.
Let’s break it down!
1️⃣ Function Declaration
We start by declaring a function named greet. This function takes three parameters: name, age, and occupation. Parameters are placeholders that we use to pass in values when calling the function.
2️⃣ Printing a Message
Inside the function, we use console.log() to print a greeting message. The message includes the name, age, and occupation parameters. The output will look something like this:
"Hello, [name]! You are [age] years old, and your job is [occupation]."
3️⃣ Calling the Function
We first call greet("Alice", 25, "teacher"), which replaces the parameters with "Alice", 25, and "teacher". The console prints:
"Hello, Alice! You are 25 years old, and your job is teacher."
4️⃣ Calling the Function Again
Next, we call the function with different arguments, greet("Bob", 30, "doctor"), which prints:
"Hello, Bob! You are 30 years old, and your job is doctor."
Finally, we call the function once more with greet("Johny", 89, "sales manager"), printing:
"Hello, Johny! You are 89 years old, and your job is sales manager."