Does Javascript run lines of code in order? and finish processing then move on?

Viewed 2838

I am trying to write some code in Javascript for first time, and I am guessing I dont get something conceptually!

The following code for me works fine :

var db = new alasql.Database("db");
db.exec('CREATE TABLE IF NOT EXISTS Myonetwo;');

var aaa = db.exec('select * into Myonetwo from json("http://localhost:8080/app1")',[],function(res){
    db.exec('select * from Myonetwo;',[],function(bbb){

            console.log(bbb.length);    
        });
});

But this one which is the same but not function inside function embedded, Does not work.

var db = new alasql.Database("db");
db.exec('CREATE TABLE IF NOT EXISTS Myonetwo;');

var aaa = db.exec('select * into Myonetwo from json("http://localhost:8080/app1")');
var bbb = db.exec('select * from Myonetwo;');
console.log(bbb.length);

Also Is getting result as a function defined as one of arguments something usuall for all Javascripts?

4 Answers
Related