Difference Between (Function(){})(); and Function(){}();

What is the difference between function and Function

Go through this tutorial

Defining functions
The Function constructor

https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope

Difference between (function(){})(); and function(){}();

Peter Michaux discusses the difference in An Important Pair of Parens.

Basically the parentheses are a convention to denote that an immediately invoked function expression is following, not a plain function. Especially if the function body is lengthy, this reduces surprises,

What is the Difference between function and function() When I call them in javascript?

words evaluates as a function.

words() calls that function and evaluates as the resulting return value.


The value you assign to onclick needs to be the function you want to get called when the click happens.

If you want the words function to be called, you have to assign that.

what is the difference between .function() and a function(args) in javascript

This is a function. It is called as function()

function test(a, b) {  return a * b;}
console.log(test(2,3));

difference between function($) and $(function())

They may look similar, but they are completely unrelated.

This is called an Immediately Invoked Function Expression (IIFE). These are not specific to jQuery, but in this case, it ensures that within the body of this function, $ will refer to jQuery, even if something outside the function has overwritten the global $ variable with something else. It is a defensive practice for minimizing conflicts with other libraries.

An additional benefit is that any variables declared within this function will not be added to the global scope. Even without jQuery, this is a common practice used to help modularize code and avoid polluting the global scope.

(function($) {
"use strict";

})(jQuery);

This tells jQuery to execute the specified function when the DOM is "ready":

$(function() {
run_code();
});

difference between function() and function

The first example that you mentioned(the above code) maps the function len to the target variable df["col1"]

df["col2"] = df["col1"].apply(len)

Whenever we have to map a function to any iterable object, the syntax needs the function to be without parenthesis.
In your case, df["col1"] must be having elements whose length can be calculated. And it will return a Pandas Series will lengths of all the elements.
Take the following example.

a = ["1", "2","3","4"]
z = list( map( int, a ) ) >> [1, 2, 3, 4]

Here, we mapped the builtin int function(which does typecasting), to the entire list.

The second example that you mentioned would give out the length of the df["col1"] series.

len(df["col1"])

It won't do any operations on the elements within that Series.
Take the following example.

a = ["1", "2","3","4"]
z = len(a) >> 4

Since, on both the occasions, the function len was fed an iterable object, it didn't give any error. But, the outputs are completely different as I explained!

What's the difference between function and function() in C#?

  • function refers the address of a function you can call
  • function() gets the return
    value of a function
  • A third way could be () => function() which
    creates a new anonymous function which is calling function (a simple wrapper in this case)

Since function() returns no other function

Thread t = new Thread(function()); 

would not work because a thread needs a function to call. This means you have to use

Thread t = new Thread(function); 

or

Thread t = new Thread(() => function());

to pass a function to a thread.

What is the difference between function and function*

Generators created with function are part of earlier ES6 draft.

//They have differrent prototypes
console.log(a.prototype.constructor.constructor,b.prototype.constructor.constructor);//function Function() function GeneratorFunction()
let a1=a(10);
let b1=b(10);
//both create generators...
console.log(a1,b1);//Generator { } Generator { }
//but different generators: one returns value, another returns an object of special format
console.log(a1.next(),b1.next());//100 Object { value: 1000, done: false }
for(let a2 of a1)console.log(a2);
for(let b2 of b1)console.log(b2);
//They are equal when used in for ... of.


Related Topics



Leave a reply



Submit