I often see code like the following in JavaScript:  func1: function() {       return array1.pop();     }   What is the difference between the above and something like this:  function func1 (){          return array1.pop(); }   Are the above two the same thing with different way of writing? The first one looks like a switch statement to me. Sorry if this question is too simple but JavaScript books seldom uses the first syntax if this is just the matter of syntax issue; the main reason for me to ask this question in StackOverflow.
647
I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.  The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.  The two ways are:  var functionOne = function() {     // Some code };     function functionTwo() {     // Some code }   What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?
114724
I'm trying to iterate through an array of elements. jQuery's documentation says:       Returning non-false is the same as a continue statement in a for loop, it will skip immediately to the next iteration.   I've tried calling 'return non-false;' and 'non-false;' (sans return) neither of which skip to the next iteration. Instead, they break the loop. What am i missing?
23938
So this is a piecewise defined function I have that I need to talk about:     f(a,b) = \left\{      \begin{array}{lr}        \text{open} &amp; : \text{RMSD}_\text{s-open}\ge6, \text{RMSD}_\text{closed}\ge6\\        \text{closed} &amp; : \text{RMSD}_\text{closed}\le2 \\        \text{semiopen} &amp; : \text{RMSD}_\text{s-open}\le2\\        \text{transition} &amp; :f(a,b)\notin\{\text{open}, \text{closed}, \text{semiopen}\} \\       \end{array}    \right.   So what's the way to align up the colons (conditions) so that it looks all nice and pretty?   Also, if I want to describe transition to be the value of the function when none of the conditions of the previous 3 are satisfied, is the way I wrote it out with f(a,b) not belonging to the set {open,closed,semiopen} a good way of writing it? seems really unprofessional...
28825
These seem to be very similar as they both separate two operands. When would one be used over the other? Is there any difference in the math spacing surrounding them?  How would the spacing in these relate to to the spacing produced by \mathop?
111110
I'm a bit confused as to how to get two method to call each other (i.e., have A() call B() and B() call A()). It seems that F# only 'sees' the method after it's been encountered in code, so if it hasn't, it just says value or constructor has not been defined.  Am I missing something very basic here?
15717
I'd like to do something like this:  &gt;&gt; foo = @() functionCall1() functionCall2()   So that when I said:  &gt;&gt; foo()   It would execute functionCall1() and then execute functionCall2().  (I feel that I need something like the )  EDIT:  functionCall1 and functionCall2 are not necessarily functions that return values.
42746
Should I use exit() or just return statements in main()? Personally I favor the return statements because I feel it's like reading any other function and the flow control when I'm reading the code is smooth (in my opinion). And even if I want to refactor the main() function, having return seems like a better choice than exit().  Does exit() do anything special that return doesn't?
88330
I've seen some people using void operator in their code. I have also seen this in href attributes: javascript:void(0) which doesn't seem any better than javascript:;  So, what is the justification of using the void operator?
47989
Okay, we know that the following two lines are equivalent -    (0 == i) (i == 0)   Also, the first method was encouraged in the past because that would have allowed the compiler to give an error message if you accidentally used '=' instead of '=='.  My question is - in today's generation of pretty slick IDE's and intelligent compilers, do you still recommend the first method?    In particular, this question popped into my mind when I saw the following code -   if(DialogResult.OK == MessageBox.Show("Message")) ...    In my opinion, I would never recommend the above. Any second opinions?
42370
What is the most recommended/best way to stop multiple instances of a setTimeout function from being created (in javascript)?  An example (psuedo code):  function mouseClick() {    moveDiv("div_0001", mouseX, mouseY); }  function moveDiv(objID, destX, destY) {    //some code that moves the div closer to destination    ...    ...    ...     setTimeout("moveDiv(objID, destX, destY)", 1000);    ...    ...    ... }   My issue is that if the user clicks the mouse multiple times, I have multiple instances of moveDiv() getting called.  The option I have seen is to create a flag, that only allows the timeout to be called if no other instance is available...is that the best way to go?  I hope that makes it clear....
2571
What is the correct (most efficient) way to define the main() function in C and C++ — int main() or void main() — and why? And how about the arguments? If int main() then return 1 or return 0?  There are numerous duplicates of this question, including:       — For C++, with a very good answer indeed.     Related:
41914
Consider:  int testfunc1 (const int a) {   return a; }  int testfunc2 (int const a) {   return a; }   Are these two functions the same in every aspect or is there a difference?  I'm interested in an answer for the C language, but if there is something interesting in the C++ language, I'd like to know as well.
51606
Possible Duplicate:          This is something I haven't quite figured out yet, but I have been using function(){}() just because my VIM syntax highlight screws up if I add the parenthesis, although I've seen (function(){})() around many times, maybe its an IE thing?  edit:  var singleton = function() {     // code }();  var singleton = (function() {     // code })();
29396
I'm wondering whether there is a difference between these two expressions. I never know which one to use. Google seems to return the same amount of results for both, so I suppose there might be a difference.        What are the alternatives for this project?     What are the alternatives to this project?
36511
I understand passing in a function to another function as a callback and having it execute, but I'm not understanding the best implementation to do that. I'm looking for a very basic example, like this:  var myCallBackExample = {     myFirstFunction : function( param1, param2, callback ) {         // Do something with param1 and param2.         if ( arguments.length == 3 ) {             // Execute callback function.             // What is the "best" way to do this?         }     },     mySecondFunction : function() {         myFirstFunction( false, true, function() {             // When this anonymous function is called, execute it.         });     } };   In myFirstFunction, if I do return new callback(), then it works and executes the anonymous function, but that doesn't seem like the correct approach to me.
7669
What's the difference between JavaScript and Java?
107627
Is it the same convention as those used in known programming languages such as Java and C? I'm trying to create a lot of variables and I want it to start with a number, but I'm not sure if it's okay.