1
00:00:02,130 --> 00:00:09,120
Typically it's a good idea in programming, not just in Javascript but especially in Javascript, to aim

2
00:00:09,120 --> 00:00:14,070
for pure functions without side effects simply because they are predictable

3
00:00:14,130 --> 00:00:20,010
and if someone calls them without knowing the function definition, it's always good if you can rely on

4
00:00:20,010 --> 00:00:24,420
the fact that this function doesn't do anything strange behind the scenes.

5
00:00:24,420 --> 00:00:30,150
Now that being said, when you're building an application, when you're writing code, it will be impossible

6
00:00:30,150 --> 00:00:34,980
for you to avoid introducing side effects at some point of time.

7
00:00:35,040 --> 00:00:41,370
A function might need to set up some event listener or might need to send some data to a server and

8
00:00:41,370 --> 00:00:43,940
that is absolutely fine.

9
00:00:44,000 --> 00:00:50,850
The goal just is to minimize the amount of functions which are impure or which have side effects, just

10
00:00:50,850 --> 00:00:54,010
work with your code in a logical way,

11
00:00:54,120 --> 00:00:57,410
try to keep your functions predictable and pure

12
00:00:57,510 --> 00:01:02,940
and if you then occasionally have some functions that need to perform a side effect or that needs to

13
00:01:02,940 --> 00:01:06,480
be impure, that's absolutely fine.

14
00:01:06,480 --> 00:01:12,450
Maybe just try to be clear regarding the function naming that this might be a function that does something

15
00:01:12,660 --> 00:01:13,800
as a side effect,

16
00:01:13,830 --> 00:01:20,160
for example a function which is named send data to server would be expected to send some data to a

17
00:01:20,160 --> 00:01:22,290
server and it wouldn't come as a surprise

18
00:01:22,290 --> 00:01:29,280
that this function as a side effect produces an HTTP request. A function which is just called add

19
00:01:29,280 --> 00:01:36,150
on the other hand should probably not create some side effect or be impure because a function with this

20
00:01:36,150 --> 00:01:36,680
name,

21
00:01:36,720 --> 00:01:40,430
well we would expect this to be pure, right?

22
00:01:40,680 --> 00:01:47,340
As always, it comes with experience and now of course it's OK to not be perfect regarding that, you should

23
00:01:47,340 --> 00:01:54,150
definitely be aware of this concept of pure functions though and as I said, aim for more pure functions

24
00:01:54,330 --> 00:01:57,990
and less impure functions that might introduce side effects.
