This is really basic javascript here and probably pretty silly to ask but what is the difference between:  a) function variable(){}; b) var variable = function() {};  I think the second one executes as soon as the browser reads it, am I correct?
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?
86767
Why is it that in a C# switch statement, for a variable used in multiple cases, you only declare it in the first case?  For example, the following throws the error "A local variable named 'variable' is already defined in this scope".  switch (Type) {     case Type.A:             string variable = "x";                 break;     case Type.B:             string variable = "y";                 break; }   However, per the logic, the initial declaration should not be hit if the type is Type.B. Do all variables within a switch statement exist in a single scope, and are they created/allocated before any logic is processed?
1371
I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference?  A (quite pointless) example in Java:  a) declaration before loop:  double intermediateResult; for(int i=0; i &lt; 1000; i++){     intermediateResult = i;     System.out.println(intermediateResult); }   b) declaration (repeatedly) inside loop:  for(int i=0; i &lt; 1000; i++){     double intermediateResult = i;     System.out.println(intermediateResult); }   Which one is better, a or b?   I suspect that repeated variable declaration (example b) creates more overhead in theory, but that compilers are smart enough so that it doesn't matter. Example b has the advantage of being more compact and limiting the scope of the variable to where it is used. Still, I tend to code according example a.  Edit: I am especially interested in the Java case.
106335
What does the following mean?  Class.Function(variable := 1 + 1)   What is this operator called, and what does it do?
2664
In python, is there a difference between calling clear() and assigning {} to a dictionary? If yes, what is it? Example:d = {"stuff":"things"} d.clear()   #this way d = {}      #vs this way
588
JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function.  How do you do the reverse, and add a function to an "object"?  This works:  var foo = function() { return 1; }; foo.baz = "qqqq";   At this point, foo() calls the function, and foo.baz has the value "qqqq".  However, if you do the property assignment part first, how do you subsequently assign a function to the variable?  var bar = { baz: "qqqq" };   What can I do now to arrange for bar.baz to have the value "qqqq" and bar() to call the function?
107888
I'm new to shell scripting and I came across these expressions   ${var:-val} and ${var-val}  ${var:+val} and ${var+val}  ${var:=val} and ${var=val}  so how are they evaluated and what are the differences between them
4564
I can write  VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}"   the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
46765
Take the below code:  private void anEvent(object sender, EventArgs e) {     //some code }     What is the difference between the following ?  [object].[event] += anEvent;  //and  [object].[event] += new EventHandler(anEvent);   [UPDATE]  Apparently, there is no difference between the two...the former is just syntactic sugar of the latter.
4059
The situation is somewhat like-  var someVar = some_other_function(); someObj.addEventListener("click", function(){     some_function(someVar); }, false);   The problem is that the value of someVar is not visible inside the listener function of the addEventListener, where it is probably being treated as a new variable.
13804
I hope this qualifies as a programming question, as in any programming tutorial, you eventually come across 'foo' in the code examples. (yeah, right?)  what does 'foo' really mean?  If it is meant to mean nothing, when did it begin to be used so?
7669
What's the difference between JavaScript and Java?
115050
What is the correct output (meaning correct by the ECMA standard) of the following program?  function nl(x) { document.write(x + "&lt;br&gt;"); } nl(Function.prototype); nl(Function.prototype.prototype); nl(Function.prototype.prototype == Object.prototype); nl(Function.prototype.prototype.prototype);   Chrome and IE6 agree in saying:   function Empty() {} null for Chrome / undefined for IE6 false   and then crashing.  Mozilla outputs:  function () { } [object Object] false undefined   Are either of these correct? It seems that the Mozilla one does better, but that the best output is  function () { } [object Object] true undefined
9968
I've been making a concerted effort to improve my javascript skills lately by reading as much javascript code as I can. In doing this I've sometimes seen the javascript: prefix appended to the front of event handler attributes in HTML element tags. What's the purpose of this prefix? Basically, is there any appreciable difference between:  onchange="javascript: myFunction(this)"   and  onchange="myFunction(this)"   ?
119239
I have a variable, x, and I want to know whether it is pointing to a function or not.  I had hoped I could do something like:  &gt;&gt;&gt; isinstance(x, function)   But that gives me:  Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in ? NameError: name 'function' is not defined   The reason I picked that is because  &gt;&gt;&gt; type(x) &lt;type 'function'&gt;
24071
I'm trying to understand Python's approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within main(), but not the value of n?  def f(n, x):     n = 2     x.append(4)     print('In f():', n, x)  def main():     n = 1     x = [0,1,2,3]     print('Before:', n, x)     f(n, x)     print('After: ', n, x)  main()   Output:  Before: 1 [0, 1, 2, 3] In f(): 2 [0, 1, 2, 3, 4] After:  1 [0, 1, 2, 3, 4]
8265
I have now seen 2 methods for determining if an argument has been passed to a JavaScript function. I'm wondering if one method is better than the other or if one is just bad to use?   function Test(argument1, argument2) {       if (Test.arguments.length == 1) argument2 = 'blah';        alert(argument2);  }   Test('test');   Or   function Test(argument1, argument2) {       argument2 = argument2 || 'blah';        alert(argument2);  }   Test('test');   As far as I can tell, they both result in the same thing, but I've only used the first one before in production.  Another Option as mentioned by :  function Test(argument1, argument2) {     if(argument2 === null) {         argument2 = 'blah';     }      alert(argument2); }   As per Juan's comment, it would be better to change Tom's suggestion to:  function Test(argument1, argument2) {     if(argument2 === undefined) {         argument2 = 'blah';     }      alert(argument2); }