Skip to content

Commit 65520ee

Browse files
committed
added some code blocks
1 parent 3f92d0b commit 65520ee

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

README.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Displays a message to the user and also takes input from the user. It returns th
325325

326326
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.
327327

328-
javascript
328+
```javascript
329329
function callback() {
330330
console.log("Callback function");
331331
}
@@ -334,11 +334,11 @@ function parentFunction(callback) {
334334
console.log("Parent function");
335335
callback();
336336
}
337-
337+
```
338338

339339
If the callback is an anonymous function, then we can also directly call the function at the time of parent call.
340340

341-
javascript
341+
```javascript
342342
function parentFunction(callback) {
343343
console.log("Parent function");
344344
callback();
@@ -347,49 +347,44 @@ function parentFunction(callback) {
347347
parentFunction(function() {
348348
console.log("Callback function");
349349
});
350-
350+
```
351351

352352
## Arrow functions
353353

354354
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.
355355

356356
It is named an arrow function, because of the arrow symbol `=>` in the syntax.
357357

358-
javascript
358+
```javascript
359359
var functionName = (param1, param2, ...) => {
360360
// function body
361361
return value;
362362
}
363-
363+
```
364364

365365
If the function has only one statement, then we can remove the curly braces and the return keyword.
366366

367-
javascript
367+
```javascript
368368
var functionName = (param1, param2, ...) => statement;
369-
369+
```
370370

371371
If the function has only one parameter, then we can remove the parenthesis.
372372

373-
javascript
373+
```javascript
374374
var functionName = param1 => {
375375
// function body
376376
return value;
377377
}
378-
378+
```
379379

380380
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.
381381

382382
## Promises
383383

384384
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.
385385

386-
javascript
387-
388-
389-
390386
```javascript
391387
var name = prompt("Enter your name");
392388

393389
console.log(name);
394-
```
395-
390+
```

0 commit comments

Comments
 (0)