Javascript, functional programming and parallel processing

functional programmingjavascript

When I use jquery library I notice that the code will continue execution regardless the previous line complete the execution. More precisely while using jquery ajax, it will continue execution without waiting for the ajax result. Is this because javascript takes advantage of parallel processing? Or to which category this can be referred to. Also can we call javascript as a functional programming language.?
It will be greatly appreciated if someone could explain this briefly. Thanks in advance.

Best Answer

Here is the deal.

1) You can use JavaScript as a functional language. I do so every day! its a great way to write code in JavaScript. The array operations in recent versions of JavaScript and the fact that the JavaScript function has all the power of a lambda in other languages make this easy to do. I would not call JavaScript a functional language but would call it a multi para-dime language.

2) There is only one thread of operation in JavaScript, however many things including Ajax operate in an Asynchronous manor. So when you make an Ajax call it returns right away and when server returns a value it sends an event that contains the return value.

3) JavaScript also lets you plan events for some time in the future. So you can tell it "In 500ms run this function"

There is a chapter on functional javascript in Programming HTML5 Applications this will be out in August. There should be a preview version of the book out sooner.