r/node • • Apr 14 '24

JavaScript Functions - 4 Ways

Post image
208 Upvotes

79 comments sorted by

View all comments

38

u/damnNamesAreTaken Apr 14 '24

As someone who doesn't really use JavaScript much, what was wrong with the function declaration form and why are the rest needed? I learned JS before the newer ways existed and never really kept up.

8

u/SparserLogic Apr 14 '24

They are handled differently by the compiler when it comes to where the function is scoped in memory. Variables are treated like other variables rather than globally like a traditional function.

5

u/RaveMittens Apr 14 '24

the compiler

The interpreter?

5

u/MaxUumen Apr 14 '24

The engine

3

u/RaveMittens Apr 14 '24

The runtime

26

u/SparserLogic Apr 14 '24

The thing that does the thing.

2

u/wherewereat Apr 14 '24

The motor

2

u/SparserLogic Apr 14 '24

The fire 🔥🔥🔥

0

u/0xhjkl Apr 15 '24

the object

0

u/[deleted] Apr 15 '24

[deleted]

→ More replies (0)

3

u/noXi0uz Apr 15 '24

All major JS engines use a JIT compiler

4

u/armano2 Apr 14 '24

its actually a compiler, compilation is usually done "before" execution, but technically this is still a compilation

read more. https://v8.dev/blog/background-compilation

1

u/shitty_mcfucklestick Apr 15 '24

A series of short gasps were heard, and the room fell silent as all eyes turned to /u/SparserLogic. Did they really know JavaScript, or are they an undercover desktop C programmer person trying to infiltrate the sub?

Tune in next Friday!

2

u/SparserLogic Apr 15 '24

Jokes on you all, I'm just three raccoons in a trench coat.