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: notes/English/20-function.md
+12-14Lines changed: 12 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# function
2
2
3
-
### What is function in JavaScript ?
3
+
### What is function ?
4
4
5
5
In JavaScript, a function is a block of code that can be executed by calling it by its name. Functions are a fundamental building block in JavaScript and are used to encapsulate and reuse code.
6
6
@@ -28,7 +28,7 @@ function add(a, b) {
28
28
let result = add(3, 4); // result = 7
29
29
```
30
30
31
-
### What is Function declaration in JavaScript ?
31
+
### What is Function declaration ?
32
32
33
33
In JavaScript, a function declaration is a way to define a function by using the function keyword, followed by the function name, a set of parentheses, and a block of code within curly braces. The function name is followed by the function keyword, the function parameters are enclosed in parenthesis and the function body is enclosed in curly braces.
34
34
@@ -61,7 +61,7 @@ It's important to note that function declaration should be defined before they a
61
61
62
62
Function declarations are a common way to define functions in JavaScript and are widely used in the language. They are also easy to understand and use, making them a good choice for many programming tasks.
63
63
64
-
### What is Function expression in JavaScript ?
64
+
### What is Function expression ?
65
65
66
66
In JavaScript, a function expression is a way to define a function by assigning it to a variable. It is similar to a function declaration, but instead of using the function keyword, a function expression is assigned to a variable using the assignment operator (=).
67
67
@@ -94,7 +94,7 @@ In this example, the add function takes two parameters, a and b, and returns the
94
94
95
95
Function expressions are also often used as callback functions, for example when a function is passed as an argument to another function:
96
96
97
-
### What is Arrow function in JavaScript ?
97
+
### What is Arrow function ?
98
98
99
99
In JavaScript, an arrow function is a shorthand syntax for defining a function. It is also known as a "fat arrow" function because it uses the "=>" symbol to define the function. Arrow functions were introduced in ECMAScript 6 (ES6) and are considered more concise and easier to read than traditional function expressions or declarations.
### Difference between function expression and arrow function in JavaScript ?
158
+
### Difference between function expression and arrow function ?
159
159
160
160
A function expression is a way of defining a function in JavaScript using the function keyword, such as:
161
161
@@ -186,7 +186,7 @@ Arrow functions do not have their own this, they use this of the surrounding sco
186
186
187
187
In general, arrow functions are shorter and easier to read than function expressions, but they have some limitations. It's a matter of preference which one to use, depending on the specific use case.
188
188
189
-
### What is Anonymous function in javaScript ?
189
+
### What is Anonymous function ?
190
190
191
191
An anonymous function in JavaScript is a function that is defined without a name. Anonymous functions are often used as arguments for other functions, such as callbacks and event handlers. They can also be assigned to variables and used just like named functions.
192
192
@@ -220,7 +220,7 @@ setTimeout(()=> {
220
220
221
221
In general, anonymous functions are used when a function is only needed once and will not be reused elsewhere in the code.
222
222
223
-
### What is Function invoking/calling in javascript ?
223
+
### What is Function invoking/calling ?
224
224
225
225
In JavaScript, a function can be invoked or called by using the function's name followed by parentheses, like this:
It's important to note that a function must be defined before it can be invoked. If a function is invoked before it is defined, it will cause an error.
255
255
256
-
### What is Function calling from other function in javascript ?
256
+
### What is Function calling from other function ?
257
257
258
258
In JavaScript, a function can be called from within another function by simply invoking the function by its name, followed by parentheses to include any necessary arguments.
259
259
@@ -277,7 +277,7 @@ In the example above, the outerFunction calls the innerFunction by its name, inn
277
277
278
278
When the outerFunction is called, it will log "This is the outer function." and then call innerFunction, which will log "This is the inner function."
279
279
280
-
### What is Function as values in javaScript ?
280
+
### What is function as values ?
281
281
282
282
In JavaScript, functions are first-class citizens, which means they can be treated like any other value, such as a number or a string. This means that they can be assigned to variables, passed as arguments to other functions, and returned from functions.
283
283
@@ -318,7 +318,7 @@ In the above example, the returnFunction returns an anonymous function that is a
318
318
319
319
In JavaScript, functions are also objects, and they have additional properties and methods that can be accessed and used like any other object.
320
320
321
-
### What is Parameters in JavaScript ?
321
+
### What are parameters in JavaScript ?
322
322
323
323
In JavaScript, parameters are variables that are used as placeholders for the values that are passed to a function when it is called. These values are known as arguments. When a function is called, the arguments are assigned to the corresponding parameters in the function definition.
324
324
@@ -338,7 +338,7 @@ let result = add(5, 3);
338
338
339
339
In this case, the value 5 is assigned to the parameter x and the value 3 is assigned to the parameter y
340
340
341
-
### What is Arguments in JavaScript ?
341
+
### What are arguments in JavaScript ?
342
342
343
343
In JavaScript, arguments are the values passed to a function when it is called. These values are assigned to the corresponding parameters in the function definition.
344
344
@@ -368,8 +368,6 @@ return x + y;
368
368
369
369
In this example, the function add takes two parameters, x and y. When the function is called, the values passed as arguments are assigned to these parameters, like this:
370
370
371
-
csharp
372
-
373
371
let result = add(5, 3);
374
372
375
373
In this case, the value 5 is passed as the first argument and the value 3 is passed as the second argument to the function add.
@@ -388,6 +386,6 @@ In this example, myFunction is called with three arguments: 1, "hello" and true,
388
386
389
387
It's worth noting that the arguments object is not an array and it doesn't have array methods like slice, map, filter etc. However, it can be converted to an array using Array.from(arguments) or using spread operator [...arguments]
390
388
391
-
### What is Arguments Object in functions in javaScript ?
389
+
### What is arguments Object in functions ?
392
390
393
391
In JavaScript, the arguments object is a special object that is available within the scope of all function calls. It contains an array-like collection of the arguments passed to the function. The arguments object allows a function to access the parameters passed to it, even if the function was not defined with a specific number of arguments. This can be useful for creating flexible or reusable functions. However, the arguments object is not an actual Array, and it does not have all of the methods of an Array.
0 commit comments