Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Javascript, async functions behave differently between Mac and Windows/Linux

await/async seem to behave differently on Chrome and Safari on Mac, compared to Chrome on Windows and Linux.

<select id="dbgselect">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

<script>
    async function dbg(type) {
        console.log(`A [${type}]`);
        await dbg2(type);
        console.log(`B [${type}]`);
    }
    
    async function dbg2(type) {
        console.log(`C [${type}]`);
    }
    
    document.getElementById("dbgselect").oninput = () => { dbg("input"); };
    document.getElementById("dbgselect").onchange = () => { dbg("change"); };
</script>

When making a selection in the dropdown, the output on Linux/Windows (on Chrome) is:

A [input]
C [input]
A [change]
C [change]
B [input]
B [change]

The output on Mac (on both Chrome and Safari):

A [input]
C [input]
B [input]
A [change]
C [change]
B [change]

HOWEVER - if I add this at the bottom, to invoke dbg outside the context of an event:

setTimeout(() => {
    dbg("input");
    dbg("change");
}, 0);

Then the result on Mac changes, and becomes the same as on Linux and Windows (i.e. A,C,A,C,B,B instead of A,C,B,A,C,B).

My questions:

  1. Is either of these implementations a bug? (i.e. a violation of some standard).

  2. Is this difference in behavior documented or discussed anywhere? I couldn't find.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!