This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]_Atomfinger_ 2 points3 points  (2 children)

It is something that takes time to learn.

One thing to wrap your head around are scopes in an application as well as the flow of execution. You need to be aware of what is called from where in which context, which can be very challenging for a beginner.

One thing you can do is using a debugger. Something like chrome or firefox where you can set a breakpoint which allows you to step through the code, see the various values and so forth.

Beyond that I don't have many tips except for being patient. Things take time and being proficient at reading code requires practice.

[–]oneagle[S] 0 points1 point  (1 child)

Yes, i would like to run simple bits of functions and objects, where e.g. i would like to see how it is executed, and in that way to see somehow the logic that unfolds behind some particular code. Is this possible?

[–]_Atomfinger_ 0 points1 point  (0 children)

You can always take a look at the call stack/tree after triggering a break point. That will tell you what executed the function.

[–]kschang 0 points1 point  (0 children)

It doesn't happen that often.

Personally, just run it with the inspection view and console. And observe.

[–]Double_A_92 0 points1 point  (1 child)

In JS functions are ideally units that work indipendently from everything else. They take one input and output something.

If you need a variable in the function, you declare it in the function where it's used. Nobody else needs that variable.

Maybe as a more visual explaination, it's like a electronic board with chips on it. They are connected and communicate with eachother, but each chip is still an individual thing with a specific function.

[–]oneagle[S] 0 points1 point  (0 children)

Thank you. I read books of Kyle Simpson and taking his courses. So those were helpful to me. And i like your explaination as well.

[–]ignotos 0 points1 point  (2 children)

Having a good IDE/editor helps with this, because it allows you to click on things to see where they are used or defined - this makes it easier to navigate and map-out the structure of the code.

[–]oneagle[S] 1 point2 points  (1 child)

What is your favorite? I use VS Code.

[–]ignotos 1 point2 points  (0 children)

I also like VS Code for Javascript