Function Declarations vs Function Expressions

preview_player
Показать описание
Today we're going to learn about the subtle but important differences between a function declaration and a function expression!

It's a sneaky little difference but one that is valuable to be aware of!

---

Рекомендации по теме
Комментарии
Автор

I've watched a few videos explaining this, and yours is by far the most straight to the point and easy to understand! Thank you :D

jasonng
Автор

Finally I've seen someone who actually knows JS. Thanks for teaching.

lastidea
Автор

I've always figured that functions live in their own space and gets called with the declaration. Though if you put the declaration above and then have a slow (or lazyloaded?) page it will throw an error since it hasn't yet gotten the function in question.

The reason it doesn't work between declaration and const is because those are things that js will run and they run things from top to bottom.

Of course you know this, just that it always felt natural for me.

ForsmanTomas
Автор

I think the two main advantages of function expressions (may regular functions or arrow functions) are:
1- It forces you to write better your code (depending on hosting is a grubby practice).
2- It demands less memory heap since the value of your function (your expressions) are not saved in memory until the interpreter reads the line where you initialize your function.

What do you think about it? Let me know!

danielvega
Автор

Not gonna lie i died of laughter at 5:15 when it sounded like he said "fucktion"

davidpicarazzi
Автор

Which one to use? More common and why? Thnx.

arunavamukherjee
Автор

Nice, straightforward to the point vid. Amazingly hard to find those on YT. People over complicate this subject way too much.

Martin
Автор

Another fun fact about function expressions is that you can give them a name, just like a function declaration. Unlike declarations, however, the name is only valid inside the body of the function. For example:

cb() {
// ...
requestAnimationFrame(cb)
})

cb() // cb is not defined

jed_fox
Автор

Thanks a ton for making this short and sweet video. This was super helpful and straight to the point. Thanks, again 🤝🏼

amkhrjee
Автор

You're a wizard Harry, thank you. I was having trouble understanding the difference.

DepressedLemur
Автор

Awesome and easy to understand! SUBSCRIBED !!!!

mrzack
Автор

thank you so much this helps me figuring out why they're different types of function, and now i know! Subscribed!

annisaautami
Автор

whats the use of function expression instead of declaration then?

icetmzz
Автор

that was awesome and easy to understand!
thank you sir!!

muhammadtayyab
Автор

When you say "the variable is not hoisted" is that actually correct? I thought a const variable is hoisted but it's just set to uninitialized?

CathalMacDonnacha
Автор

Brilliant video! I've just subscribed :D

funkyasthmatic
Автор

use Extension of vsc Quokka.js
bcoz output will be display Right of console.log
no need of run or anything else,

SapanKumarDas
Автор

Could you please create a videos on ReactJS PWA

rajashekhar
Автор

3:40 pft dude how many times should they tell you to take yo pills

XJacksonvilleX