Hello React Summit US! I wish you a warm welcome to today's talk. Today we're going to talk about something called Web API. But before we do that, we will need to take a small step back and go through some JavaScript basics.
If we see this example, and I ask you the question, what the order of the logs would be in the console, probably most of you would say 1, 3, 2. And that is correct. But how do we know that? How do we know how setTimeout behaves?
As we know, JavaScript is a single thread language. Let's visualize this a bit. There is a call stack, we execute the first function which is synchronous, and then we log the 1 as a value immediately. But then the second one is asynchronous, and it needs to go somewhere else, not to block that single thread. And it goes to the queue once the timer is finished. In the meantime, the call stack continues with executing the functions, then event loop checks if the call stack is empty, and pushes back the callback with the value of 2. But the main question is, where does the setTimeOut wait while we continue with the execution of our code?
If we Google this function, the first result we get is this one. So there is MDN documentation where we can see some stuff about setTimeOut function. And here we can see that it's under a tab WebAPIs. If we click that, we can see that basically WebAPIs is a collection, a list of APIs and interfaces which we may use right out of the box when developing web applications. Basically, it's a functionality provided by a runtime environments. In this case, our browsers. And if we scroll a bit, we can see that there are a lot of APIs, a really, really long list of APIs. And here we can maybe observe that there are some quite commonly known and used APIs, like WebRTC, session storage, local storage, file upload API, a DOM API, and so on. But looking through this list, I was wondering, what are the some of the exotic and not so commonly used APIs that we may use which can give us our web application certain superpowers in certain use cases? So basically, we're here to find out that today. And like we established, the answer to this question about set timeout is Web API, which is basically a collection of built-in interfaces that allow developers to interact with our pages and provide some fancy functionality.
I'm going to quickly introduce myself. When I was in high school, I always wanted to study psychology. Now I work my dream job at Wega IT based in Noišac, Serbia, where I work as a development which means that I teach people soft skills, how to communicate with the clients, how to deal with stress, how to do presentations like this, why not, and so on. My name is Nikola Mitrović and these are my Web APIs highlights for you for today. OK, now we go to our first example for today. Let's say we have a page like this and there is nothing there but the background, but once we scroll a bit down we can start observing that there is something in the bottom left corner. It's a small astronaut, which when fully visible says, hello world. Once we scroll a bit up and the astronaut is not fully visible, the message goes away. We scroll again a bit down and again, once the astronaut is fully visible again he says hello world.
Comments