Skip to content

Instantly share code, notes, and snippets.

for(var i=0; i<10; i++){
console.log(i);
}
var i = 0;
function forloop(){
if(i<10){
console.log(i);
i++;
setTimeout(forloop, 0);
}
}
forloop();
(function forloop(i){
if(i<10){
console.log(i);
setTimeout(function(){ forloop(i+1); }, 0);
}
})(0);
(function a(){
console.log("hello!");
})();
(function(){
// inner scope.. you can't touch me from outside!
var i = 0;
function forloop(){
if(i<10){
console.log(i);
i++;
setTimeout(forloop, 0);
}
}
$.getJSON('/data0.json', function(data) {
console.log("yay! Data0 is ready!");
});
$.getJSON('/data0.json', function(data) {
console.log("yay! Data0 is ready!");
// ok, now use that to get the next piece of data.
$.getJSON('/data1.json', function(data) {
console.log("yay! Data1 is ready!");
// ok, now use that to get the next piece of data.
$.getJSON('/data2.json', function(data) {
console.log("yay! Data2 is ready!");
// ok, now use that to get the next piece of data.
$.getJSON('/data3.json', function(data) {
(function(){
var i = 0;
function forloop(){
if(i<5){
$.getJSON('/data'+i+'.json', function(data) {
console.log("yay! Data"+i+" is ready!");
i++;
forloop();
});
}else{
for(var i=0; i<10; i++){
for(var j=0; j<10; j++){
console.log(i,j);
}
}
console.log("all done.");
(function(){
var i = 0;
function forloop1(){
if(i<10){
(function(){
var j = 0;
function forloop2(){
if(j<10){
console.log(i,j);
j++;