Why different output in IE and FF?
In IE its showing : Hello and In FF its showing : Hi
var message = "Hi";
setTimeout(function(){alert(message);},10);
setTimeout(function(){message = "Hello";},0);
what is standarad? which browser is doing it right?
Note: if i convert 10 to 11 in FF then it shows Hello
Modern JavaScript is a “safe” programming language. It does not provide low-level access to memory or the CPU, because it was initially created for browsers which do not require it. JavaScript's capabilities greatly depend on the environment it's running in.
How to detect the user browser ( Safari, Chrome, IE, Firefox and Opera ) using JavaScript ? The browser on which the current page is opening can be checked using JavaScript. The userAgent property of the navigator object is used to return the user-agent header string sent by the browser.
It's important to know that each browser has its own tooling, including its own version of JavaScript based on the ECMAscript standards. Yes, that's right. ECMA only sets the standards for JavaScript, and every browser has its own version of JavaScript.
Firefox handles small delays differently to IE. Firefox have a min delay time of 10ms (which isn't exact either). See the notes of https://developer.mozilla.org/en/window.setTimeout for more info.
On my PC I ran it in both FF and IE, and I had exactly the opposite results.
The reason for this is your timeout is just 10 milliseconds long. The resolution of Timers on Windows is actually about 10ms, so it's possible that either timeout could happen first. To be really sure that one thing happens before the other, you should definitely have a wider gap between timeouts.
And even then, you shouldn't expect it to always work :-)
If you really want to do things in the same order, keep it in the same line of code, or set flags saying whether or not a particular action has been completed, and check that before doing a second one which relies on the first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With