-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path22_function.js
27 lines (16 loc) · 1.24 KB
/
22_function.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
// In JavaScript, a function is a block of reusable code that performs a specific task.Functions are a fundamental building block of programming and are used to organize and modularize code.
// Here's an example of a simple function:
// function greet(name) {
// console.log("Hello, " + name + "!");
// }
// This function is called greet and it takes one parameter called name.When the function is called, it will log a message to the console that says "Hello, " followed by the value of the name parameter.
// To call the greet function, you simply need to provide a value for the name parameter:
// greet("John"); // logs "Hello, John!"
// Functions can also return values.Here's an example of a function that takes two parameters and returns their sum:
// function add(a, b) {
// return a + b;
// }
// This function is called add and it takes two parameters called a and b.When the function is called, it will return the sum of a and b.
// To use the add function, you can call it like this:
// var result = add(2, 3); // result is now 5
// In this example, the add function is called with the values 2 and 3 as its parameters.The function returns the sum of those two values, which is 5. The result is then assigned to a variable called result.