What is javascript synchronous / Asynchronous Programming in hindi

What is javascript synchronous Asynchronous Programming

Introduction

हेलो दोस्तों आज हम इस post में javascript Asynchronous Programming technique के बारे में जानेगे साथ में synchronous Programming and Asynchronous Programming के बीच के different के बारेमे बी जानेगे!.

What is JavaScript Synchronous Programming

JavaScript Synchronous Programming में tasks sequentially based एक के बाद एक execute होता है, मतलब की
एक task का execution ख़तम होने के बाद ही अगले task को execute किया जाता!. इसका मतलब यह है की
यदि किसी task को पूरा होने में लंबा time लगता है, तो उस task के समाप्त होने तक अगले किसी भी प्रकार के task का execute नहीं होगा!.

Example:

<script>
 console.log("Task 1");
 console.log("Task 2");
 console.log("Task 3");
</script>

ऊपर के example में देख सकते है सभी tasks को एक के बाद एक execute किया जाता है, और प्रोग्राम अगले task पर जाने से पहले  सभी console.log() statement के finish होने की wiat करता है!. इसके results एक synchronous execution में होता है!. जहा output का order “Task 1″,”Task 2″,”Task 3” होता है!.

What is Javascript Asynchronous Programming

Javascript Asynchronous Programming में tasks non-blockingly रूप से execute होता है!.
Program अगले tasks पर जाने से पहले किसी tasks के पूरा होने का wait नहीं करना होता है!. इसके बजाय यह एक task को start करता है और तुरंत अगले task के लिए जाता है, जबकि पहला task भी background में चलता रहता है!. एक बार task का execution पूरा हो जाने के बाद result को manage करने के लिए callback function start हो जाता है!.

Example:

<script>
 console.log("Task 1");
 setTimeout(function() {
  console.log("Task 2");
 }, 2000);
 console.log("Task 3");
</script>

ऊपर ke example में setTimeout() function एक asynchronous है!. यह specific time के bad प्रोवाइड किये गए callback function के execution को schedules करता है!. और program specific time finish होने का wait नहीं करता है और तुरंत  अगले tasks पर move हो जाता है!. और kuch time के बाद callback function का execution किया जाता है, और congole में “Task 2” log किया जाता है!.

Asynchronous programming का इस्तेमाल time-consuming operations के लिए किया जाता है जैसे की HTTP requests करना, database या file को reading/writing और users interactions को handle करना. Asynchronous रूप से executing करके, जिससे program लंबे time तक चलने वाले task के पूरा होने की wait करते हुवे दूसरे operation कर सकता है!.

Javascript एक programming language है जो synchronous और Asynchronous programing दोनों को supports करती है!. default रूप से, javascript code को synchronous रूप से execute किया जाता है!. हलाकि javascript Asynchronous operation के साथ काम करने के लिए mechanisms और APIs बी provide करता है, जिससे developers को
callbacks, promises, और async/await syntax का इस्तेमाल करके synchronous code लिखने की अनुमति मिलती है!.

 

Leave a Comment

Your email address will not be published. Required fields are marked *