Password Strength Checker In jQuery In Hindi
Optional chaining in JavaScript In Hindi | JS Optional chaining In Hindi
Ternary Operator In JavaScript In Hindi | JavaScript Conditional Operator In Hindi
JavaScript "new Function" Syntax : JS "new Function" Syntax
Best Branded Mouse Under 500 In India Available On Amazon
PHP object Type Casting In Hindi | PHP object In Hindi
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
JS setInterval
आपने हमारी website पर कई examples में आपने setInterval()
function का use देखा होगा , और आज इस blog में इसी function के बारे में detail से पढ़ेंगे।
Actually कई बार हमें ऐसी जरूरत पड़ती हैं जहाँ हम किसी block of code / function को किसी particular time के बाद repeatedly execute कराना चाहते हैं , ऐसी situation में हम setInterval()
function का use करते हैं।
actually इसे एक तरह से Scheduler
की तरह use किया जाता है , जहाँ दिए गए time के बाद block of code run होता रहता है।
let time_id = setInterval(callback_function, [delay in miliseconds], [arg1], [arg2], ...);
Explanation
callback_function : setInterval() function का पहला argument एक Callback Function है , जिसे या तो आप पहले से defined किसी function का नाम या directly function pass कर सकते हैं।
delay : delay वह time है जिसके बाद आप callback function run करना चाहते हैं , इसकी value milliseconds
में होती है। जैसे आपने 10 second time set किया तो हर 10 second में pass किया गया callback function run होता रहेगा।
Argument list : arg1 , arg2 , arg3 . . . वो arguments हैं जिन्हे आप callback functions में handle करना चाहते हैं।
●●●
function sayHello() {
console.log('Hello');
}
// delay for 2 seconds only.
setInterval(sayHello, 2000);
Output
Hello Hello // after 2 seconds Hello // after 4 seconds Hello // after 6 seconds . . and so on.
example में हमें 2 seconds
का delay किया है तो जब तक code remove नहीं कर देते या tab close नहीं कर देते तब तक हर 2 second बाद sayHello()
function call होता रहेगा।
Loading ...
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook