So many ways of using Functions?

I just realised like 4 different ways of writting functions?

Whats the difference between:

var funcStyleOne = function(){};

or

var functionStyleTwo = function newStyle(){};

or

function(){}

or

var ObjectFunc = new Function();

or

function Hello(){}

They are all types of functions but i can’t seem to understand the difference between them. They all kinda do the same thing? Are they just different styles and me as the programmer simply choose whichever style fits my choosing? Or is there a requirement when using one over the other. I know to avoid the one with the “new” since it requires more memory. How about the simple “function hello(){}”? Should i choose that one since it resembles what i use form other languages (C/C++)?

Sorta, but not really.

http://stackoverflow.com/a/338053/1312971

If you’re coming from C/C++, the first thing you’re probably going to have a hard time getting over with JavaScript is that it’s very free form. But it could be worse.

From my understanding, its a preference to choose whichever style i need !

That version is extremely inefficient and should be avoided. It effectively reads the content of the function as text and then eval() s it into code. The situations where it is needed are extremely rare.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.