Using an IIFE in Javascript can help solve strange scope issues #shorts

preview_player
Показать описание

My VSCode Extensions:
- theme: material community high contrast
- fonts: Menlo, Monaco, 'Courier New', monospace
- errors: Error Lens
- extra git help: Git Lens
- tailwind css intellisense
- indent rainbow
- material icon theme
- prettier & eslint
- ES7+ React Snippets
Рекомендации по теме
Комментарии
Автор

okay that could have been useful a few years ago. Butnow that we have "let", this is just a party trick

yadusolparterre
Автор

Every time a dev uses var instead of const or let, a puppy dies.

IainSimmons
Автор

thank you CaptainSparklez for the coding tip

thekeyboard
Автор

Also setTimeout can have morethan 2 parameter so we can pass our variable like that too

fazalmohamed
Автор

I remember these times. Thank god es6 happened.

Revadike
Автор

I'm surprised to be learning new js still, great examples bro

ChadGauthier
Автор

That's really neat, thanks for sharing!

Mark-njzh
Автор

The final result past like a lighting, I have to see again, bro?

bestapps
Автор

It's like useEffect hook in react 😂

shiekhpalace
Автор

happy birthday!! 🎉 you look younger than me though 🙂

v.
Автор

Is an IIFE necessary for this use-case? I mean isn't it possible to create a normal function and just call it with the parameter?

MaxProgramming
Автор

X.x why not just put the loop inside the setTimeout. It pretty obvious it would be undefined xD. Oh was the intent to have a delay for each print?

flamehiro
Автор

What theme are you using in the editor?

minegamer
Автор

Hi Dev i am a newbie, Can you suggest me which programming language should I start with

cooldude
Автор

I didn't understand using let instead of var, how issue could have solved? Basically still we must get undefined, can someone please tell me...

akshaygadekar
Автор

Time of unfunny jokes: "what's this?"

archsapostlestapostleofth
Автор

"Javascript", just shit the anonymous funcs here and there and that's it.

the_xyzt_eht
Автор

The tip is to stop using *var* in the middle of 2022 as there is no reason to, and make good use of good practices, for..of exists for a reason and setTimeout can take arguments to be passed to the callback, II(A)FE is only useful if you are not using ES Modules so as not to pollute the global environment and must be used in the global scope, all your code must be inside IIFE.

"use strict";

(/* async */ () => {
const names = ["Bob", "Sally"];

for (const name of names) {
setTimeout(console.log, 1000, name);
}
})();

hadawardgz
Автор

Well, just simply never use var since it's bad practice

YamiSuzume