This video.
Let's talk about if we that is immediately invoked function expression.
So if you functions a function that is executed as soon as it is created.
Wow.
So what are some of the use cases here?
Well, let's assume that you want a function that's going to be executed as soon as your page load.
Then we need what is called if and for if it functions to it, execute once and that is all.
So let's see how we are going to implement if it functions well, this idea or concept is commonly used
in redux.
If you are familiar with React and Redux, go.
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
invoked.
We are going to create a simple function and for the meantime let's create our normal function.
And then we call it, and let's see how we can pass our custom function to an F function to be called.
So let's see, the first function is going to be log.
Hello, very simple function.
Look.
Hello.
And this function will take in anything good.
So here, just console.log.
Let's say this one are going to be.
Hello, this is.
Hello, normal function.
This a normal function.
Right.
So if I call this function called log.
Hello indeed I won't to see as normal function down in my console.
So let's see how we are going to create.
If function well, we can do so using normal function, syntax or arrow function and we are going to
adopt these two techniques.
So let's start from using normal function.
So using, let's say F.
So the first step is bring in your parentheses as that.
And then inside this, that's where we are going to create our function.
So let's say function and this function will have no name as this.
So if I open my services, I can log anything here to the console and let's see.
So if I save it, nothing happens because we're not calling this function, right?
So to call it you bring your syntax as that if I save it.
Nine See that if we see that it has been called automatically down here.
So what about if I give it a name?
Let's say say hello.
As that.
So if I save this one, indeed I see.
Say hello.
Because if this function is going to call immediately, I think giving it a name doesn't make sense
to me, but it's also depends how you want it.
Maybe in future you want to know what kind of function or which logic that if it doing so you can pass
in or you can give it a name through it.
So we can also call any function inside this particular function.
So let's say that you want a function that's going to be called automatically so I can bring in my log.
Hello.
Inside, look.
Hello.
Is that if I save it?
And now it's that?
Hello.
I'm normal function but instead we pass in this normal function to our function to your code.
So let's see how we can create this one using arrow function.
The syntax will be crazy.
So let's see.
So now remember we bring in our parentheses as that and inside goes my function and here we go, arrow
function.
And this function is going to retain an expression so I can ignore the basis so I can even console.log
anything.
Let's say I know that if we.
As that.
And if I save it, you see that nothing happened because I didn't call this function.
So I'll break my parentheses as that when I save it.
Well, nothing happens because I need to wrap this one inside a parentheses as that because I forgot
to wrap it inside as that when I save it.
You see that another iffy.
Great.
Remember, I have to wrap everything inside that parentheses, and after that I bring a parentheses
to call the function as that.
So it is what you call if.