-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path25_parameter.js
35 lines (19 loc) · 1.79 KB
/
25_parameter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// In JavaScript, a parameter is a named variable that is listed as part of a function's definition. When you call a function, you pass arguments to the function, which are the actual values that are passed to the function to be used as the parameter values.
// Here's an example of a function that takes two parameters:
// function addNumbers(a, b) {
// return a + b;
// }
// In this example, the addNumbers function takes two parameters called a and b.When you call this function, you need to pass two arguments to it, like this:
// var result = addNumbers(2, 3);
// console.log(result); // logs 5
// In this example, the values 2 and 3 are passed as arguments to the addNumbers function, and they are assigned to the parameters a and b, respectively.The function adds those two values together and returns the result.
// A default parameter is a parameter that has a default value assigned to it.If you don't pass an argument for a parameter with a default value, the default value will be used instead.
// Here's an example of a function that uses default parameters:
// function greet(name = "World") {
// return "Hello, " + name + "!";
// }
// In this example, the greet function takes one parameter called name, but it has a default value of "World".If you call the greet function without passing an argument, it will use the default value of "World".If you pass an argument, it will use that argument instead.
// console.log(greet()); // logs "Hello, World!"
// console.log(greet("John")); // logs "Hello, John!"
// In this example, the first call to the greet function uses the default value of "World", and the second call passes the argument "John".
// I hope this helps you understand parameters, default parameters, and arguments in JavaScript! Let me know if you have any further questions.