Thuta Learning
ရှာဖွေရန်
AdvancedProgrammingbeginner

Async JS Intro

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

JavaScript သည် single-threaded ဖြစ်သော်လည်း asynchronous operations များဖြင့် အချိန်ကြာသော tasks (e.g., network requests) များကို program ၏ main thread ကို block မလုပ်ဘဲ လုပ်ဆောင်နိုင်သည်။

Asynchronous JS ကို ကိုင်တွယ်ရန် နည်းလမ်းများမှာ:

1. Callbacks: (Old way)

2. Promises: (Better way)

3. Async/Await: (Modern, cleanest way)

javascript
console.log("Start");

// setTimeout is an asynchronous function.
setTimeout(() => {
  console.log("This message is shown after 2 seconds.");
}, 2000);

console.log("End");
You should see
Start End (2 seconds later) This message is shown after 2 seconds.
Async JS Intro | Thuta Learning