InterviewHubPRO
Section Overview
Q334

Question 334 of 521

Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

64%
JavaScript Internals (521 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

Is postMessages synchronous

The postMessages are synchronous in IE8 browser but they are asynchronous in IE9 and all other modern browsers (i.e, IE9+, Firefox, Chrome, Safari).Due to this asynchronous behaviour, we use a callback mechanism when the postMessage is returned.

Practical Code Example

javascript
// Is postMessage synchronous?
// NO. postMessage is asynchronous. The message is queued and delivered via the browser event loop:
console.log('1. Before postMessage');
window.postMessage('hello', '*');
console.log('2. After postMessage');
// Listener will execute in the next tick of the event loop!