1
00:00:00,390 --> 00:00:10,110
This is the section that I'm waiting for, and that is synchronous versus asynchronous programming.

2
00:00:10,920 --> 00:00:19,530
After we've gone through this section, it will help us to write fast, good performance code.

3
00:00:19,830 --> 00:00:29,820
And above all, it will help us to develop real world applications like news app, text to speech application,

4
00:00:29,820 --> 00:00:35,650
translation app and many more using external APIs.

5
00:00:35,670 --> 00:00:37,410
So let's get started.

6
00:00:40,510 --> 00:00:48,220
So in this particular video, we would differentiate differences between synchronous versus asynchronous

7
00:00:48,220 --> 00:00:49,090
programming.

8
00:00:49,510 --> 00:00:55,630
Let's see the differences between synchronous versus asynchronous programming.

9
00:00:55,900 --> 00:01:01,120
Well, synchronous code is executed in a linear fashion.

10
00:01:01,120 --> 00:01:04,269
That means one line at a time.

11
00:01:04,750 --> 00:01:12,400
But for asynchronous programming or code, on the other hand, it execute code out of order, meaning

12
00:01:12,400 --> 00:01:13,540
in power.

13
00:01:14,240 --> 00:01:20,780
Which means that until this point, all the code that you have been reading are all synchronous code

14
00:01:20,780 --> 00:01:24,890
because it execute one after the other.

15
00:01:25,340 --> 00:01:33,170
And if you remember, on the high level of JavaScript, we talk about JavaScript as a single threaded

16
00:01:33,170 --> 00:01:34,520
programming language.

17
00:01:34,640 --> 00:01:39,260
That is why a code is being executed in order.

18
00:01:39,530 --> 00:01:46,760
So if one code takes, let's say, 10 minutes to execute the other code below, it will wait until it

19
00:01:46,760 --> 00:01:47,420
finished.

20
00:01:47,600 --> 00:01:51,640
So this is what you call blocking or single threaded.

21
00:01:51,650 --> 00:01:54,470
So when you say synchronize is also same as what?

22
00:01:54,470 --> 00:01:55,640
Blocking code.

23
00:01:56,150 --> 00:01:59,900
But asynchronous programming, on the other hand, don't do that.

24
00:02:00,110 --> 00:02:05,030
But instead it can execute code in power or concurrently.

25
00:02:05,090 --> 00:02:06,440
So why is it so?

26
00:02:06,470 --> 00:02:14,030
And this is a time I will show you why we have this kind of features in JavaScript as asynchronous code.

27
00:02:14,270 --> 00:02:15,050
So.

28
00:02:16,390 --> 00:02:24,520
Here comes the question you may be asking that, well, if JavaScript is a single threaded and one thread

29
00:02:24,520 --> 00:02:29,760
manages or the code is running, why is it that we can run code in power?

30
00:02:29,770 --> 00:02:33,190
So as you move on you will see the differences.

31
00:02:33,490 --> 00:02:38,950
So let's say in details, differences between these two programming style.

32
00:02:39,040 --> 00:02:43,840
Well, we often shorthand asynchronous as async.

33
00:02:43,840 --> 00:02:47,710
So when I say async, I mean asynchronous or right.

34
00:02:47,710 --> 00:02:55,480
So for synchronous programming, it is what you call single threaded, meaning it uses one thread to

35
00:02:55,480 --> 00:03:03,430
manage all our code execution, but for asynchronous code it is also called multithreaded, meaning

36
00:03:03,430 --> 00:03:07,300
we have more than one thread to manage code execution.

37
00:03:07,300 --> 00:03:08,560
So why is it so?

38
00:03:08,560 --> 00:03:13,990
By default JavaScript is a single thread, so I'll prove to you as you move on.

39
00:03:14,290 --> 00:03:23,290
And again, synchronous code is also called code blocking because if a function or code takes some time

40
00:03:23,290 --> 00:03:29,470
to run and if otherwise below it cannot run, it means that it's blocking the other code from running.

41
00:03:29,830 --> 00:03:34,390
But for asynchronous code it is non blocking code.

42
00:03:34,420 --> 00:03:40,390
As you saw on the high level of JavaScript, we talk about JavaScript as non blocking.

43
00:03:40,390 --> 00:03:40,840
Right.

44
00:03:40,840 --> 00:03:46,330
And I showed you how I used that timeout to make this happen again.

45
00:03:46,330 --> 00:03:51,280
We will revisit this technique again for synchronous code.

46
00:03:51,280 --> 00:03:54,700
It handle one request at a time.

47
00:03:54,700 --> 00:04:03,340
When you say requests, it simply means that getting or requesting a certain data from certain API into

48
00:04:03,340 --> 00:04:04,570
your application.

49
00:04:05,050 --> 00:04:09,160
In that case, you're going to hand it down one one at a time.

50
00:04:09,400 --> 00:04:14,410
But for asynchronous, it handled multiple requests at a time.

51
00:04:15,250 --> 00:04:23,770
And again, synchronous code gives poor user experience whilst asynchronous improve user experience.

52
00:04:23,770 --> 00:04:28,210
This means how fast your application loads or run.

53
00:04:28,660 --> 00:04:36,040
So with these two programming techniques, one can affect what user experience because it's slow and

54
00:04:36,040 --> 00:04:43,450
the other one increase or improve user experience because it runs fast, because code doesn't block

55
00:04:43,480 --> 00:04:46,210
other code from running again.

56
00:04:46,210 --> 00:04:47,950
Let's see more in details.

57
00:04:47,950 --> 00:04:51,100
Let's talk about synchronous programming.

58
00:04:51,520 --> 00:04:52,000
All right.

59
00:04:52,000 --> 00:04:57,100
So in this video, let's start with synchronous programming in more details.

