List of Best digital marketing companies in India for SEO services

List of Best digital marketing companies in India for SEO services


It's going to be getting into some of the basics of callbacks and promises. And both of these are ways that allow us to write asynchronous code in javascript and callbacks are kind of the issue where we're going to look at it and we're going to take a look at Promises which kind of improve upon the form of callbacks best digital marketing companies in India So you know a lot of people prefer promises of callbacks myself included for various reasons so you know as usual I think it's important I understand where we're coming from in terms of how new developments improve our quality of life.

You know in terms of writing javascript but callbacks are still a very powerful feature that we do need to understand in terms of Javascript. So, first of all, look for top digital agencies let's get into callbacks and we will see what kind of problems this is designed to solve. Right. We'll see what you mean when we say Asynchronous JavaScript.

So, first of all, let's talk about callbacks are just functions so a callback function is just a function that is passed to another function. As a parameter and I'll make another line here actually. So this inner function is called At some point during the execution of the containing function. In other words, it's called back at some specified point inside the containing function's body it's a callback best digital marketing companies in India This is not really a technical term this is just a commonly used term in terms of functional programming which a lot of javascript is concerned with functional programming. It's a callback.

So, in other words, it's called back at some unspecified point inside the containing body's function and you may be saying Well that sounds difficult. What does that look like? Well, first of all, let's take a look at what this is designed to solve and we need to understand something about javascript which is the fact that it is synchronous in its execution of code. And what I mean by that is let's see best digital marketing companies in India if we define a couple of functions so the function should go first for example and all this will do initially we'll just say I should always go first and then we have another function should go second.

  • And as you can imagine this one should always get a second should always go second. And this code will be synchronous provided we invoke these functions in the same order.
  • Right so I could do should go first and then it should go second. And let's keep it on our console over here. You can see that it ran as we expected it to run it so we invoke this function write we in the media we executed that function then we immediately executed the second function and that's fine.
  • When your code is fully synchronous. But that's not always the case often, especially once we get you to know later on when we're doing things like getting requests to fetch some data and we need to wait for that data to come back.
  • We may want to delay executing another function until we have that data because we need that data to you know to transform it somehow or to add it to the dorm or just do something with it.
  • And in our simple example let's say we want to wait until we see this line of code before we log the second line of code best digital marketing companies in India. It is kind of in the names that this should always go first if there is any kind of delay.
  • Well, let's observe what happens. I get a set time for that and sometimes it takes a function that I'm going to rate the ear six-way. And it also takes time to wait until it executes that function essentially.
  • So instead of just logging, I'm going to put that in the set time a function. And now let's see if our code behaves as we expect it to behave. Let's see. Run and then. Oh no. Something is wrong here.

All right so you see I should always go second. That doesn't sound right because that's going first and then, later on, we're getting this line of code. So what's happening is so we invoke this initial function and then it just starts invoking this function and then we just immediately move on and we start invoking the second function. We don't need to wait for this one to come back before the best digital marketing companies in India we start executing the next line of code. And that's what we mean when we talk about javascript being synchronous readjust immediately invokes this one says OK this one is started and then immediately invoke this one we haven't told it to wait until this function is completed before invoking a second function. So how can we solve that problem?

Well, of course, we could just add another line console log down below that kind of defeats the purpose of us using a callback though. So let's rewrite this code using a callback instead. And we're going to tell the code they don't execute this function until we finish this line of code. And that's going to look something like this. So instead of just directly invoking should go second I'm going to pass a parameter to should go first just to tell it hey I'm going to be passing you something here and I'm just going to call it a callback. And this could be called anything.

And it's just like passing in any other parameter into a function as we know we can pass strings arrays any type of object essentially into a function as a parameter and functions are no different functions are just objects in javascript and we can pass them to other functions. Now, this can be treated just like any other function which means we can invoke this function here like so.

Notice that we use the argument name with parameter name and you invoke it just like any other function. Now we have to pass this parameter to. Should go first. And how do we do that we just give it the name should go second like so. Notice that I'm not invoking a function which would be like this. I'm passing a reference to the function and this function will be invoked at best digital marketing companies in India some point inside the execution of this function. So let's see if our logic was sound clear. We run it again. Hey, we're waiting. And now we get our results. And that's exactly what we wanted.

So I should always go first as soon as this goes out to the con. We invoked our inner function which if you follow along was a reference to should go seconds and you know if you make a mistake and you accidentally invoke this function Let's see what happens when we invoke it first and then we didn't pass it a reference of the function we pass it a function that's been executed. So at that point, it doesn't understand that. So that's the difference between using the brackets and not as a pretty simple example. Let's do another example where we actually use some kind of data. So I'm going to stop invoking this function I'm going to leave it here as a reference for later but let's say we have a function and we do kind of a classic some numbers. Takes and no.

And some kind of callback which you often see abbreviated as just Sibi could be anything really in terms of what you choose to define it as. But let's say cost some value equals one plus two. And we want to do something with some value so we're going to invoke our callback and pass it some value. So that means we need to define another function here to do something best digital marketing companies in India with some value. So let's see we do log a summed value and it's going to take in a value of some sort. And this one as well as to a simple console log these batiks here the sum total is and will give it the vowel that was passed in. Now if we want to invoke this function and pass it some numbers we can say sum up numbers. Let's give it and we also do need to pass it in the reference to this function so we can do that like so log summed. Valley it clear this. Try it out. It works totally as expected.