How to use the built-in timer functions which allow you delay your function calls. Code GIST: gist.github.com/prof3ssorSt3v...
Пікірлер: 66
@rotrose75314 жыл бұрын
Can not thank you enough for these god-sent tutorials. My only hope is that please make more and more. Your knowledge can help many people like me, and hope more students will find this channel, It is a waste of resource when I see the number of viewers.
@malikbrett20402 жыл бұрын
I dont mean to be so off topic but does any of you know of a way to get back into an instagram account? I was dumb forgot my password. I appreciate any help you can offer me.
@WalrusMcDonald12n2na22 жыл бұрын
You explained this perfectly thank you so much. Was confused about assigning the timeouts to a variable name.
@chesterxp5082 жыл бұрын
Brilliant tutorials :)
@MiSt33003 жыл бұрын
A bit long, but nevertheless effective. Thank you for your help, I couldn't get my head around these w3 schools and stack overflow tutorials (;
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
You have to be very careful with anything that you get from either of those resources.
@jrs_devs3 жыл бұрын
I love the sound of the mouse click, together with the calm voice it's very relaxing
@KieranX5 жыл бұрын
Thnx this was helpfull
@andrzejsotnikow74943 жыл бұрын
Thank you!
@kelvinsantosalm4 жыл бұрын
Thank you.
@arctan24 жыл бұрын
thank you so much
@juliethabila-rn9uv4 ай бұрын
The best
@mostafagh35732 жыл бұрын
great, thank u
@FordExplorer-rm6ew4 жыл бұрын
Would there be a way to use setTimeout &| setInterval to send continuous http requests to something? Kind of like a scuffed slow http?
@SteveGriffith-Prof3ssorSt3v34 жыл бұрын
Sure. You can put anything you want inside the functions that you pass to setTimeout or setInterval.
@justaprogrammer37645 жыл бұрын
Aside from the interval and timeout methods, those i understand, something else hit me. How is declaring a variable initiating that function or its value? function test(){ console.log('this function was executed'); } let x = test(); let y = 10; In the variable y its being internally saved on memory and not computed with until asked for, but declaring a function automatically runs it ?
@SteveGriffith-Prof3ssorSt3v35 жыл бұрын
Declaring the variable with the function doesn't run it. The parentheses after the function name are what make it run. let f = function(){ //this is a function stored inside the variable f return 'abc'; } let x = f; //now a reference to the function that is stored inside the variable f is also store in the variable x. let y = f( ); //now the function f will run and its result, 'abc' will be stored in the variable y.
@ayaanirshadbhat65673 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 I get what you said, but here's my question; -------------------------------------------------------------------------------- function log(msg) { console.log('MESSAGE', msg); clearInterval(tommy); } let tommy = setInterval(log, 500, 'Goodbye'); --------------------------------------------------------------------------------- In the code above, the last line is clearly a case of let y = f(); So if the result of f() [here setInterval] is going to be stored in y [here tommy], the function log has to run first and then the value is stored ( as per my understanding ), but here we see that the function log calls clearInterval(tommy) when the function is being run for the first time, how can tommy have a value at this point and clearInterval(tommy) not throw an error since the function hasn't completely run even once. Thanks
@bodaciouschad2 жыл бұрын
Ah. That is why you get an "invalid callback error" from setInterval(callback(deets),500); You have to use setInterval(callback,500,deets); Thank you.
@andrewgarfinkel19784 ай бұрын
What if you wanted to setInterval function to run immediately, as well as at each interval? So for the first call...you don't want any delay.
@SteveGriffith-Prof3ssorSt3v34 ай бұрын
There is no way to avoid a delay because the function being given to the timer is always placed in a holding area off the main stack. Even setting a time of zero, there will be a delay. Here is a video about this process - kzbin.info/www/bejne/rV7Nhn-OZalomck I would suggest that you use a named function inside the timer like this: setInterval( myFunc, 1000); and then you can call the function before setting the timer: myFunc( ); setInterval( myFunc, 1000);
@andrewgarfinkel19784 ай бұрын
@@SteveGriffith-Prof3ssorSt3v3 thanks. I watched a video that described JavaScript as sort of like a “one lane highway”…where there is a “main line”, and a “finish line.” Basically, all the synchronous code with go in order on the “main line.” But when something is async, it is pulled off the “main line,” and temporarily, it is pulled into “another lane on the highway,” until it is ready to go back onto the “main line” of the highway. Is this an accurate way to think of it? So basically, you are suggesting to make the first call synchronous, and the rest of them will be async?
@IvoTsochev3 жыл бұрын
I didn't get why I would want to clear the setTimeout since it's running only once?
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
You might want to clear a setTimeout BEFORE it completes for the first time.
@de-kat2 жыл бұрын
Are the Timers asynchron? Like can i run othere code while the are counting ?
@SteveGriffith-Prof3ssorSt3v32 жыл бұрын
Yes they are.
@de-kat2 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 thx
@Martin958 Жыл бұрын
What if you want setInterval( ) to run more than just once? How would you do that? And what is the point of setInterval( ) if you can't turn it off normally?
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
SetInterval automatically runs over and over and over until you stop it with clearInterval.
@Martin958 Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Yes but clearInterval( ) will stop it before it even begins as you showed. And also hiding it in another function only runs it once. It's hard to see how you would stop it after (x) number of runs.
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
@Martin958 you would need a counter variable outside the scope of the timer. Increment the counter inside the timer function. If the value exceeds your max then call clearInterval
How can I set the delay time if it's offline when the data in database is delayed after 3 minutes?
@SteveGriffith-Prof3ssorSt3v34 жыл бұрын
The timers don't care about online or offline, they just want to call a function after a delay. They will call the function regardless of any other settings or things that are going on unless the webpage is closed.
@ayroserosli43134 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Thank you for the information. Basically like this, my project is about air quality monitoring which is involve the sensor. So i need to display the status of sensor which is online when the sensor is running then if it's stop the status will display offline. So, I want to implement the delay time if the data is stop within 3 minutes the status will offline. How can I do it? :(
@SteveGriffith-Prof3ssorSt3v34 жыл бұрын
There should be some event that is triggered by the sensor to tell you when it goes online or offline. Create a listener for that event which will run a function that starts your timer.
@ayroserosli43134 жыл бұрын
Steve Griffith oh okayokay thank you so much 😊
@kllokoq3 жыл бұрын
I've been trying to figure this out, just recently started to study JS. Why does this happen if I write this: var tick = true; function ticker() { if(tick) { console.log("Tick"); tick = false; } else { console.log("Tock"); tick = true; } } setInterval (ticker, 1000); Everything works as expected. It tick tocks every second. But if I place the variable tick within the scope of the function ticker, it's value is not changed to false, and the console.log keeps printing only tick. It confuses me I feel that there is something very important for me to understand here!
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
You need to understand scope and hoisting kzbin.info/www/bejne/fqbOloOtopKLfZo kzbin.info/www/bejne/fKq6laV5j7-UrLM I have other videos on those topics too.
@kllokoq3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Thank you! This makes much more sense now!
@kllokoq3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 What I didn't like about the code I wrote in the comment is that it had this global variable. I wanted to have code with everything it needed to run, locally. And I just learned that is possible by nesting a function within a function, and creating what is called a closure! This is the new code: function x() { var tick = true; function ticker() { if(tick) { console.log("Tick"); tick = false; } else { console.log("tock"); tick = true; } } return ticker; } var test = x(); setInterval(test, 1000);
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
I have a couple videos on closures too. kzbin.info/www/bejne/pXTQfaxtmsiEiLc kzbin.info/www/bejne/gWrJm4COa6tonKc You would probably learn a lot going through my JS from the Start playlist - kzbin.info/www/bejne/sJu5d6icqZaCaLs
@kllokoq3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 I already have! I love them! I'm trying to cover the same subjects from different sources, as a way to learn through repetition and gain different perspectives!
@chvishnu435 жыл бұрын
Prepare a script please
@piyushgoswami89093 жыл бұрын
which ide is this ?
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
Brackets from Adobe, which is what I used before switching to VSCode
@muhammedcansoy14343 жыл бұрын
That ıs what I am lookıng
@chvishnu435 жыл бұрын
And also clear 120 second timer
@SteveGriffith-Prof3ssorSt3v35 жыл бұрын
I cant understand what you are saying. Please use full sentences and provide details about your questions
@chvishnu435 жыл бұрын
Please help me brother
@chvishnu435 жыл бұрын
With out login
@chvishnu435 жыл бұрын
Clear 20 second time script sir
@chvishnu435 жыл бұрын
Hi Sir PL provide a script for captcha above URL
@SteveGriffith-Prof3ssorSt3v35 жыл бұрын
Please post requests on the tutorial request video
@chvishnu435 жыл бұрын
There is 20 second time how to kill it
@SteveGriffith-Prof3ssorSt3v35 жыл бұрын
ClearTimeout or clearInterval are how you stop a timer.
@chvishnu435 жыл бұрын
Sir please create a script for automatic captcha and auto login
@chvishnu435 жыл бұрын
Open the url and next u can find out the 20 seconds countdown time
@FordExplorer-rm6ew4 жыл бұрын
@@chvishnu43 lol you need to work on those social engineering skills guy
@sethortiz6975 жыл бұрын
It's hard to focus with the keyboard clicks and the sound of the computer fan. If you used an external microphone, your videos would 1,000 more enjoyable. Otherwise awesome video.
@SteveGriffith-Prof3ssorSt3v35 жыл бұрын
yeah. Very aware. I got a good external mic over a year ago. Just my old videos that have the unfortunate audio issues.