bitwix

Tangential comments about Software Development

Saturday, March 23, 2013

The moment I lost it with JavaScript

The following code segments are from JavaScript Patterns by Stoyan Stefanou (O'Reilly 2010)
  1. Can you spot the difference?
  2. Which one is correct JavaScript?
  3. If both are correct, what is the difference in behaviour?
(function() {
 alert( "An immediate function");
}()); 
(function() {
 alert( "Also an immediate function");
})(); 
The answers are
  1. The position of brackets in the last line
  2. Both are correct
  3. There is no difference

At this point I throw the book across the room. Not that it's the book's fault.