Skip to content

Instantly share code, notes, and snippets.

@IOExceptional
Created February 1, 2015 06:30
Show Gist options
  • Save IOExceptional/e7c77984bdadf808688f to your computer and use it in GitHub Desktop.
Save IOExceptional/e7c77984bdadf808688f to your computer and use it in GitHub Desktop.
Asynchronous JavaScript is a lie!
<html>
<head>
<title>JsTestBed</title>
</head>
<body>
<h2>"Async" test</h2>
<p>
In JavaScript, asynchronous calls are a lie!<br />
What actually happens is the setTimeout(func, 0); gets put on the end of the call list.<br />
Any direct javascript functions will get prioritised and run before the function in the timeout.
</p>
<script>
var i = 0;
setTimeout(function () {
alert(i);
}, 0);
for(var x = 50000; i < x; i++){
console.log("pain");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment