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: README.md
+11-16Lines changed: 11 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -325,7 +325,7 @@ Displays a message to the user and also takes input from the user. It returns th
325
325
326
326
Callbacks are JavaScript's way of implementing asynchronous programming. A callback is a function that is passed as an argument to another function and is executed after its parent function has been completed.
327
327
328
-
javascript
328
+
```javascript
329
329
functioncallback() {
330
330
console.log("Callback function");
331
331
}
@@ -334,11 +334,11 @@ function parentFunction(callback) {
334
334
console.log("Parent function");
335
335
callback();
336
336
}
337
-
337
+
```
338
338
339
339
If the callback is an anonymous function, then we can also directly call the function at the time of parent call.
340
340
341
-
javascript
341
+
```javascript
342
342
functionparentFunction(callback) {
343
343
console.log("Parent function");
344
344
callback();
@@ -347,49 +347,44 @@ function parentFunction(callback) {
347
347
parentFunction(function() {
348
348
console.log("Callback function");
349
349
});
350
-
350
+
```
351
351
352
352
## Arrow functions
353
353
354
354
These are a type of functions that are used to write the functions in a short way. They are anonymous functions, with a special syntax.
355
355
356
356
It is named an arrow function, because of the arrow symbol `=>` in the syntax.
357
357
358
-
javascript
358
+
```javascript
359
359
varfunctionName= (param1, param2, ...) => {
360
360
// function body
361
361
return value;
362
362
}
363
-
363
+
```
364
364
365
365
If the function has only one statement, then we can remove the curly braces and the return keyword.
If the function has only one parameter, then we can remove the parenthesis.
372
372
373
-
javascript
373
+
```javascript
374
374
varfunctionName=param1=> {
375
375
// function body
376
376
return value;
377
377
}
378
-
378
+
```
379
379
380
380
They are generally used with JS's native functions like `map`, `filter`, `reduce`, etc. When we need to apply the same operation to a set of values.
381
381
382
382
## Promises
383
383
384
384
These are the basics of asynchronous programming in JS. A promise is an object that may produce a single value some time in the future. Either a resolved value or a reason that it's not resolved.
0 commit comments