Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Synchronous vs. Asynchronous Functions</title>
<meta name="viewport" content="width=device-width">
</head>
<body>
<h1>Heading</h1>
<script>
let log = console.log;
let a = 5;
let b = 50;
let a1 = (function (){ return 5 })()
let b1 = (function (){ return 50 })()
log( a1 );
log( b1 );
let a2 = function(num){ return 5*num }
let b2 = function() { return 50 }
log( a2(b2()) );
/**
setTimeout, callbacks for geolocation, Promises, fetch, ajax, filesystem interaction, database calls, even DOM event listeners
**/
let a3 = 100;
setTimeout( function(){ a3++; }, 0);
log(a3);
setTimeout( function(){ log(a3) }, 0)
let p = new Promise(function(resolve, reject){
setTimeout( function(){
resolve("Yo!");
}, 0)
});
log(p);
setTimeout(function(){
log(p);
}, 10);
log(p);
p.then(function(val){
log(val);
})
</script>
</body>
</html>
@anthonyalvarez

This comment has been minimized.

Copy link

anthonyalvarez commented Mar 29, 2018

Hello Steve Griffith,

Found your "Understanding Synchronous vs Asynchronous JavaScript" video on YouTube.
Why do some statements in this gist end with a semicolon and others do not?

For example:
Lines ending without a semicolon

  • 22
  • 24
  • 29
  • 30

On line 56, there is an ending bracket that does not have semicolons too.
})

As a JavaScript programmer, how do we know when a line ending semicolon is needed?
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.