Confused About How JavaScript Functions Handle Scope and Arguments

0
3
Asked By CuriousCoder123 On

I'm struggling to grasp a section in a JavaScript guide that explains functions, particularly about scope precedence. I've been looking at this part of the guide, and I'm curious about how the number '10' is being factored into the evaluation. Can someone break it down for me?

1 Answer

Answered By FunctionFanatic99 On

Honestly, it can be pretty messy. The outer function is returning this inner function, and then that inner function gets called right away. It's pretty much the same as doing something like this:

const fn = outside();
console.log(fn(10));

So it really is just calling that inner function with 10 as the argument right after it's defined.

JSenthusiast -

I totally get that; JavaScript can be a bit of a headache sometimes!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.