DEV Community

Different types of Functions in JavaScript

Md. Jamal Uddin on November 03, 2018

Different types of Functions in JavaScript Photo by Markus Spiske on Unsplash A JavaScript function is a block of code designed to per...
Collapse
 
gmartigny profile image
Guillaume Martigny

Nice article. Small comment, on the third arrow function example, when you write :

const noise2 = _ => console.log("Pling");
Enter fullscreen mode Exit fullscreen mode

There's an unused parameter named _ instead of no parameter. Both are valid anyway, just wanted to point out the difference ;)

Collapse
 
jaamaalxyz profile image
Md. Jamal Uddin

Yeah! It's intentional. Only for showing variation. Thanks so much for your comment.

Collapse
 
gypsydave5 profile image
David Wickes • Edited

Very comprehensive!

Couple of typos:

Your default parameters examples has ; instead of , between the arguments

const multiply = (a = 2, b = 3, c = 1) => a * b * c;
Enter fullscreen mode Exit fullscreen mode

You're missing a ' on your new Function example:

var sum = new Function('a', 'b', 'return a + b');
Enter fullscreen mode Exit fullscreen mode

(I love that you introduce the Function constructor by the way - hours of fun for everyone there)

Collapse
 
jaamaalxyz profile image
Md. Jamal Uddin • Edited

Bull's eye man! truly I have read my post more than 10 times :) and two of my friends proofread it but no one figured it out. I will be more prepared next time. thanks.

Collapse
 
victordeflos profile image
victordeflos

i am a beginner in coding i am currently finishing frond end courses and for the final test i need an idea to be able to make some program in react. please help or some page on the web where I could find examples and printed codes. thank you very much

Collapse
 
waqardm profile image
Waqar Mohammad

Nice article dude. Your English is great too. Keep it up

Collapse
 
jaamaalxyz profile image
Md. Jamal Uddin

Thanks

Collapse
 
thomasabishop profile image
Thomas Bishop

Very helpful article and admirably free of waffle. Nice work :)

Collapse
 
jaamaalxyz profile image
Md. Jamal Uddin

Thanks

Collapse
 
tamalchowdhury profile image
Tamal Chowdhury

Very in depth and helpful.

Collapse
 
jaamaalxyz profile image
Md. Jamal Uddin

Thanks man!😍

Collapse
 
alvarocaceresmu profile image
Álvaro Cáceres Muñoz

Nice article! You managed to make me understand generators for the first time XD.

By the way, could you please give me a practical use case of the Function consctructor? Thank you

Collapse
 
jaamaalxyz profile image
Md. Jamal Uddin

here is an example Function constructor with implementing a class and you know JavaScript class is a syntactic sugar over the function structure.


class Animal {
  constructor(name, energy) {
    this.name = name
    this.energy = energy
  }
  eat(amount) {
    console.log(`${this.name} is eating.`)
    this.energy += amount
  }
  sleep() {
    console.log(`${this.name} is sleeping.`)
    this.energy += length
  }
  play() {
    console.log(`${this.name} is playing.`)
    this.energy -= length
  }
}

const leo = new Animal('Leo', 7)

wanna know more, please check out this stackoverflow thread

Thanks!

Collapse
 
entrptaher profile image
Md Abu Taher

Go forth!

Collapse
 
jaamaalxyz profile image
Md. Jamal Uddin

Thanks bro 😍 to see you here.

Collapse
 
victordeflos profile image
victordeflos

and whether there is a torrent site for developers or a community.