Hello there!
I have some PHP knowledge, and now I’m trying to learn JavaScript. Because of that, I never saw something like defining a function using a function expression before.
Right now, I’m doing Learn JavaScript Syntax: Functions, and I’m having a great doubt about function expressions utility.
What are the differences between defining a function by function declarations and by function expressions?
function plantNeedsWater(day) {
// Some clean code
}
const plantNeedsWater = function(day) {
// Some clean code
}
Conventional function declarations seem cleaner to me, and it’s what I see in other languages. So, why use function expressions to define a function?