Variable scoping in Jquery/Javascript?

LINE A does appear above LINE B in the source code, but that doesn't necessarily mean that it executes sooner. That is because LINE A is inside a function expression which is passed into the process function. This process function will invoke that function expression at some time in the future.

Var ids = ; $( function () { html5sql. Process( sql, function () { // LINE A: you are populating your array here }); // LINE B: the array is still empty here }); LINE A does appear above LINE B in the source code, but that doesn't necessarily mean that it executes sooner. That is because LINE A is inside a function expression which is passed into the process function.

This process function will invoke that function expression at some time in the future. So, basically, LINE B is executed immediately, and LINE A is executed at some point in the future. The function expression is probably bound (as a handler) to a SQL-related event.

I think your explanation is a bit flawed. The code is executed in order, but the function called by html5sql() is being run asynchronously (apparently) so it hasn't assigned values to ids when the call to console. Log is made immediately afterward.

– RobG Jan 5 at 2:42 @RobG Could you be more specific? What statement from my answer is problematical? – Šime Vidas Jan 5 at 2:57 The part that says LINE A does appear above LINE B in the source code, but that doesn't necessarily mean that it executes sooner.

The code is executed in sequence, but the function it calls is asynchroonous so it's still executing when the next line is called. – RobG Jan 5 at 4:04 @RobG My statement is correct. LINE A is not executed immediately, and LINE B is executed immediately.

Therefore LINE B is executed sooner (in time) than LINE A. As a matter of fact, from the code provided by the OP, he have no guarantee that LINE A is executed at all. When the statement html5sql.

Process(...); executes, the function expression is passed into the process function - the function body of that function expression is not executed at this point. It's up to the process function to decide if it wants to invoke that function immediately... – Šime Vidas Jan 5 at 14:49 ...or bind it as an event handler so that it's invoked when an event triggers at some point in the future. Therefore, my statement - "LINE A does appear above LINE B in the source code, but that doesn't necessarily mean that it executes sooner (in time)" - is correct.

– Šime Vidas Jan 5 at 14:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions