I am new to JS and still a newbie. So I am learning new ways of using functions in JS like the arrow fucntions. const func= () => {}
We can use var and const in arrow functions Is there any way to use it the traditional function declaration methods like -
function func() { }
Among dozens of different ways of declaring a function the following 2 are the most commonly used (and favored by the JS community:
- Arrow Function:
const Foo = () => {}- Regular Function:
function () {}
And that is why you almost always see the above formats throughout the not only the beginning, but also the rest of your programming career! But that does not, necessarily, mean you cannot use some other alternatives i.e. "const/var in traditional way of declaring"
One good example can be a named function expression:
const count = function(array) { // Function expression
return // something;
}
For a better understanding, I would suggest checking out the following blog post: 6 Ways to Declare JS Functions