JSFiddle - React, Tailwind, and code Playground
by jrm2k6
JavaScript
////A
//This is an example of a synchronous function
function ssqrt(n) {
////F
return Math.sqrt(n);
////G
}
//This is an example of an asynchronous function
function asqrt(n,callback) {
////K
setTimeout(function() {
////O
callback(Math.sqrt(n));
////R
}, 10);
////L
}
////B
$(document).ready(function() {
////D
//Using a synchronous function
////E
var n = 16.0;
var s = ssqrt(n);
////H
//Code here isn't executed until
//after the square root is calculated
//Using an asynchronous function
////I
var n = 16.0;
////J
asqrt(n, function(s) {
////P
//Code in here is executed once the
//square root has been calculated
//Anything that requires the information
//from the asqrt response must be here or
//called from in here.
////Q
});
////M
//Code here is executed *before* the
//square root has even been calculated
////N
});
////C