javascript-generality
http://geekabyte.blogspot.ca/2014/01/javascript-effect-of-setting-settimeout.html
JavaScript being single threaded…When Javascript runs, it runs in a single thread of execution.
JavaScript being non blocking I/O…
I would like to see I/O operations as operations that changes the state of stuff outside the JavaScript environment. So apart from the more common I/O operations like reading/writing to files system/database, reading/writing to network resources etc. I would include DOM Manipulation too as an I/O operation. As the DOM is apart from JavaScript execution but JavaScript can be used write to the DOM and read value from the DOM.
it should be noted that I/O operations are generally expensive and takes time to completion.
So by JavaScript being non blocking I/O, it means that when it performs I/O operations, the single thread of execution does not pause and wait for the ongoing I/O operations to complete before moving on to the next task. This is possible because JavaScript makes use of callbacks for I/O operations. Which are set of instructions that can be predefined to execute whenever an I/O task completes (or in case of an Event, when an event occurs. Or in case of a Timer, when the delay expires).
When an I/O operation is defined, you always have the option to define its callback. So when the single thread encounters such an I/O instruction, it starts the execution, takes the callback for the task (if defined) and registers it to be pushed into an event queue when done and it moves on to the next task in line.
1 | "hello".substr(1); // "ello" |
charAt()
The charAt() method returns the specified character from a string.1
"hello".charAt(0); // "h"
1 | function reverse(s){ |
https://jsbin.com/gigavev/edit?js,console
1 | function isPalindrom(str) { |
Closures
http://stackoverflow.com/questions/111102/how-do-javascript-closures-work