You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: curriculum/challenges/english/25-front-end-development/review-javascript-functions/6723c5b8601a40a100bb59c9.md
+54-1Lines changed: 54 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,19 +13,72 @@ Review the concepts below to prepare for the upcoming quiz.
13
13
14
14
- Functions are reusable blocks of code that perform a specific task.
15
15
- Functions can be defined using the `function` keyword followed by a name, a list of parameters, and a block of code that performs the task.
16
+
17
+
```js
18
+
functionaddNumbers(x, y, z) {
19
+
return x + y + z;
20
+
}
21
+
22
+
console.log(addNumbers(5, 3, 8)); // Output: 16
23
+
```
24
+
16
25
- Arguments are values passed to a function when it is called.
26
+
- A function call is the process of executing a function in a program by specifying the function's name followed by parentheses, optionally including arguments inside the parentheses.
17
27
- When a function finishes its execution, it will always return a value.
18
28
- By default, the return value of a function is `undefined`.
19
29
- The `return` keyword is used to specify the value to be returned from the function and ends the function execution.
30
+
- Default parameters allow functions to have predefined values that will be used if an argument is not provided when the function is called. This makes functions more flexible and prevents errors in cases where certain arguments might be omitted.
31
+
32
+
```js
33
+
constcalculateTotal= (amount, taxRate=0.05) => {
34
+
return amount + (amount * taxRate);
35
+
};
36
+
37
+
console.log(calculateTotal(100)); // Output: 105
38
+
```
39
+
40
+
- Function Expressions are functions that you assign to variables. By doing this, you can use the function in any part of your code where the variable is accessible.
- Arrow functions are a more concise way to write functions in JavaScript.
24
-
- Arrow functions are defined using the `=>` syntax between the parameters and the function body.
53
+
54
+
```js
55
+
constcalculateArea= (length, width) => {
56
+
constarea= length * width;
57
+
return`The area of the rectangle is ${area} square units.`;
58
+
};
59
+
60
+
console.log(calculateArea(5, 10)); // Output: "The area of the rectangle is 50 square units."
61
+
```
62
+
25
63
- When defining an arrow function, you do not need the `function` keyword.
26
64
- If you are using a single parameter, you can omit the parentheses around the parameter list.
65
+
66
+
```js
67
+
constcube=x=> {
68
+
return x * x * x;
69
+
};
70
+
71
+
console.log(cube(3)); // Output: 27
72
+
```
73
+
27
74
- If the function body consists of a single expression, you can omit the curly braces and the `return` keyword.
28
75
76
+
```js
77
+
constsquare=number=> number * number;
78
+
79
+
console.log(square(5)); // Output: 25
80
+
```
81
+
29
82
## Scope in Programming
30
83
31
84
-**Global scope**: This is the outermost scope in JavaScript. Variables declared in the global scope are accessible from anywhere in the code and are called global variables.
0 commit comments