1
00:00:03,820 --> 00:00:04,900
This video.

2
00:00:04,930 --> 00:00:12,250
Let's talk about if we that is immediately invoked function expression.

3
00:00:12,820 --> 00:00:18,610
So if you functions a function that is executed as soon as it is created.

4
00:00:19,000 --> 00:00:19,600
Wow.

5
00:00:19,600 --> 00:00:22,360
So what are some of the use cases here?

6
00:00:22,390 --> 00:00:30,070
Well, let's assume that you want a function that's going to be executed as soon as your page load.

7
00:00:30,100 --> 00:00:37,100
Then we need what is called if and for if it functions to it, execute once and that is all.

8
00:00:37,120 --> 00:00:44,560
So let's see how we are going to implement if it functions well, this idea or concept is commonly used

9
00:00:44,560 --> 00:00:45,690
in redux.

10
00:00:45,700 --> 00:00:48,480
If you are familiar with React and Redux, go.

11
00:00:48,520 --> 00:00:53,650
So let's see how you're are going to create a function called iffy and let's see how it's going to be

12
00:00:53,650 --> 00:00:54,370
invoked.

13
00:00:54,700 --> 00:01:00,670
We are going to create a simple function and for the meantime let's create our normal function.

14
00:01:00,670 --> 00:01:08,180
And then we call it, and let's see how we can pass our custom function to an F function to be called.

15
00:01:08,200 --> 00:01:12,640
So let's see, the first function is going to be log.

16
00:01:13,000 --> 00:01:15,640
Hello, very simple function.

17
00:01:15,940 --> 00:01:16,450
Look.

18
00:01:16,450 --> 00:01:16,810
Hello.

19
00:01:16,810 --> 00:01:21,040
And this function will take in anything good.

20
00:01:21,040 --> 00:01:23,050
So here, just console.log.

21
00:01:23,870 --> 00:01:26,420
Let's say this one are going to be.

22
00:01:26,450 --> 00:01:27,740
Hello, this is.

23
00:01:27,740 --> 00:01:29,180
Hello, normal function.

24
00:01:30,050 --> 00:01:31,100
This a normal function.

25
00:01:31,100 --> 00:01:31,490
Right.

26
00:01:31,490 --> 00:01:35,660
So if I call this function called log.

27
00:01:35,660 --> 00:01:40,910
Hello indeed I won't to see as normal function down in my console.

28
00:01:41,120 --> 00:01:43,580
So let's see how we are going to create.

29
00:01:43,580 --> 00:01:50,450
If function well, we can do so using normal function, syntax or arrow function and we are going to

30
00:01:50,450 --> 00:01:52,280
adopt these two techniques.

31
00:01:52,280 --> 00:01:54,650
So let's start from using normal function.

32
00:01:54,650 --> 00:01:57,410
So using, let's say F.

33
00:01:57,890 --> 00:02:01,910
So the first step is bring in your parentheses as that.

34
00:02:01,910 --> 00:02:05,660
And then inside this, that's where we are going to create our function.

35
00:02:05,660 --> 00:02:11,600
So let's say function and this function will have no name as this.

36
00:02:12,170 --> 00:02:18,350
So if I open my services, I can log anything here to the console and let's see.

37
00:02:18,560 --> 00:02:23,180
So if I save it, nothing happens because we're not calling this function, right?

38
00:02:23,180 --> 00:02:29,150
So to call it you bring your syntax as that if I save it.

39
00:02:29,160 --> 00:02:34,490
Nine See that if we see that it has been called automatically down here.

40
00:02:34,850 --> 00:02:36,830
So what about if I give it a name?

41
00:02:36,830 --> 00:02:39,830
Let's say say hello.

42
00:02:43,000 --> 00:02:43,840
As that.

43
00:02:43,840 --> 00:02:46,700
So if I save this one, indeed I see.

44
00:02:46,720 --> 00:02:47,120
Say hello.

45
00:02:47,200 --> 00:02:53,590
Because if this function is going to call immediately, I think giving it a name doesn't make sense

46
00:02:53,590 --> 00:02:57,120
to me, but it's also depends how you want it.

47
00:02:57,130 --> 00:03:03,940
Maybe in future you want to know what kind of function or which logic that if it doing so you can pass

48
00:03:03,940 --> 00:03:06,640
in or you can give it a name through it.

49
00:03:06,640 --> 00:03:13,060
So we can also call any function inside this particular function.

50
00:03:13,060 --> 00:03:19,330
So let's say that you want a function that's going to be called automatically so I can bring in my log.

51
00:03:19,330 --> 00:03:19,840
Hello.

52
00:03:19,840 --> 00:03:21,400
Inside, look.

53
00:03:21,400 --> 00:03:22,000
Hello.

54
00:03:22,150 --> 00:03:23,890
Is that if I save it?

55
00:03:23,890 --> 00:03:24,850
And now it's that?

56
00:03:24,850 --> 00:03:25,270
Hello.

57
00:03:25,270 --> 00:03:32,620
I'm normal function but instead we pass in this normal function to our function to your code.

58
00:03:32,620 --> 00:03:36,670
So let's see how we can create this one using arrow function.

59
00:03:36,670 --> 00:03:38,470
The syntax will be crazy.

60
00:03:38,470 --> 00:03:39,250
So let's see.

61
00:03:39,880 --> 00:03:47,530
So now remember we bring in our parentheses as that and inside goes my function and here we go, arrow

62
00:03:47,530 --> 00:03:48,400
function.

63
00:03:48,400 --> 00:03:55,090
And this function is going to retain an expression so I can ignore the basis so I can even console.log

64
00:03:55,090 --> 00:03:55,840
anything.

65
00:03:55,870 --> 00:04:00,160
Let's say I know that if we.

66
00:04:01,270 --> 00:04:02,200
As that.

67
00:04:02,200 --> 00:04:07,060
And if I save it, you see that nothing happened because I didn't call this function.

68
00:04:07,060 --> 00:04:10,450
So I'll break my parentheses as that when I save it.

69
00:04:10,810 --> 00:04:19,269
Well, nothing happens because I need to wrap this one inside a parentheses as that because I forgot

70
00:04:19,269 --> 00:04:24,180
to wrap it inside as that when I save it.

71
00:04:24,560 --> 00:04:26,640
You see that another iffy.

72
00:04:26,830 --> 00:04:27,350
Great.

73
00:04:27,370 --> 00:04:34,870
Remember, I have to wrap everything inside that parentheses, and after that I bring a parentheses

74
00:04:34,870 --> 00:04:36,910
to call the function as that.

75
00:04:36,910 --> 00:04:38,740
So it is what you call if.

