According to Event Loop basics and the video, re-render task is executing after all JS scripts have been completed. The pixel pipeline
But if synchronously add an element to the DOM and measure width or height, without waiting for a re-render - it works! It's even possible to change element's content and measure again - still working.
So, why does this works?
let element = document.createElement('div');
Object.assign(element.style, {
'position': 'absolute',
'float': 'left',
'whiteSpace': 'nowrap',
'visibility': 'hidden',
'font': '12px arial',
'display': 'inline-block'
});
element.innerText = 'some text';
document.querySelector('body').appendChild(element);
// Why does it work? According to the video,
// I need to wait when async render task be completed, isn't it?
console.log(element.offsetWidth);