Git Product home page Git Product logo

Comments (52)

xuxuewen avatar xuxuewen commented on May 28, 2024 2

Great article!
I am a software developer from China, I like your articles very much, I want to translate them into Chinese to help more developers.
Before we translate it into Chinese and publish it on our website, I
want to ask for your permission first! This translation version is
provided for informational purposes only, and will not be used for any
commercial purpose.

In exchange, we will put the English title and link at the end of
Chinese article. If our readers want to read more about this, he/she can
click back to your website.

Thanks a lot, hope to get your help. Any more question, please let me
know.

from dmitripavlutin.com-comments.

Gleb-Gaiduk avatar Gleb-Gaiduk commented on May 28, 2024 1

Another amazing article, thank you so much!

from dmitripavlutin.com-comments.

KicaRonaldOkello avatar KicaRonaldOkello commented on May 28, 2024 1

After paying for courses, watching a lot of YouTube videos and reading a lot of articles. Finally, this article lays it out very simply. Thanks Dmitri

from dmitripavlutin.com-comments.

Vincekdinh avatar Vincekdinh commented on May 28, 2024 1

Great article! Thank you for your contribution to this world. I think you're very talented!

from dmitripavlutin.com-comments.

chikhimng avatar chikhimng commented on May 28, 2024

Thank you very much for your explanation. What is remain not clear for me is "the lexical context" Is it the same as scope?
Please mores practice examples of closure

from dmitripavlutin.com-comments.

Jocelyn59435 avatar Jocelyn59435 commented on May 28, 2024

That's awesome!! Thank you so much.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

That's awesome!! Thank you so much.

Glad you like it @Jocelyn59435.

from dmitripavlutin.com-comments.

Plunky33 avatar Plunky33 commented on May 28, 2024

Great article! Very well laid-out explanation. Thank you!

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Great article! Very well laid-out explanation. Thank you!

You're welcome @Plunky33!

from dmitripavlutin.com-comments.

duc168 avatar duc168 commented on May 28, 2024

Great explanation. Keep up the good job.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Great explanation. Keep up the good job.

Thanks @duc168!

from dmitripavlutin.com-comments.

maiajrs avatar maiajrs commented on May 28, 2024

Thank you very much for the explanation. When you use "in other words" it helps a lot!

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

When you use "in other words" it helps a lot!

The idea is to show a different point of view. Glad you find it useful @jrmaiafs!

from dmitripavlutin.com-comments.

ramzahn avatar ramzahn commented on May 28, 2024

Thank you for your well written and very concise article.

P. S.
I think there is one small stepping stone missing in the continuity of your explanation (imho).

"Let’s make a change: innerFunc() to be invoked outside of its lexical scope (outside of outerFunc()). Would innerFunc() still be able to access outerVar?"

You propose to show to how access the inner function from the outside context.
This should have led to an error.

The vital concept of returning the inner function is introduced without an explanation as to WHY.
"Now innerFunc() is executed outside of its lexical scope"

I hope i can make myself understandable. This is just meant as a suggestion.

from dmitripavlutin.com-comments.

pavithra0116 avatar pavithra0116 commented on May 28, 2024

Really an awesome explanation ! Thank you so much :)

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Really an awesome explanation ! Thank you so much :)

You're welcome @pavithra0116!

from dmitripavlutin.com-comments.

Steph638 avatar Steph638 commented on May 28, 2024

I made a lot of progress thanks to your simple and precise explanations.
2 comments :

  1. at the end of "3.The Lexical Scope", a small typo : "The lexical scope of innerFunc() consists of func() and global scope." innerFunc should be replaced by innerOfFunc.
  2. My real question :
    Near the middle of "4.The Closure", you say : "Now innerFunc() is executed outside of its lexical scope.". I don't understand. I think innerFunc() is now executed in the global scope, which is, like you told in my first comment, part of the lexical scope of innerFunc. Can you explain that ?

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

@Steph638 Your comments are correct, including the question about lexical scope and global scope. I need to update the post.

from dmitripavlutin.com-comments.

masiucd avatar masiucd commented on May 28, 2024

Well explained Dimitri

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Well explained Dimitri

Thanks Marcell (@masiucd)!

from dmitripavlutin.com-comments.

skane2600 avatar skane2600 commented on May 28, 2024

The explanations are pretty clear until you get into the built-in functions because some of the information is implicit. handleClick captures countClicked because countClicked is in global scope or some other scope that encases handleClick that isn't explicitly shown? And myText.innerText is also global and thus is in a parent scope of handleClick? Am I getting that right? Unfortunately Event Handlers are usually the first exposure people learning JavaScript have to closures but also the one that is more difficult to explain IMO. Thanks for your explanation.

from dmitripavlutin.com-comments.

Danskydan avatar Danskydan commented on May 28, 2024

What if the multiply() function in example in 5.3 were changed as follows:

function multiply(a) {
return function executeMultiply(b) {
return a * b * Math.random();
}
}

Would double and triple close over whatever Math.random() returned when double and triple were defined?

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

What if the multiply() function in example in 5.3 were changed as follows:

function multiply(a) {
return function executeMultiply(b) {
return a * b * Math.random();
}
}

Would double and triple close over whatever Math.random() returned when double and triple were defined?

Nope, Math.random() would execute when calculating the final result only.

from dmitripavlutin.com-comments.

stardustman avatar stardustman commented on May 28, 2024

under the hood,how implements closure?Is it copy the outter function‘s value into the inner function when lexing time?

from dmitripavlutin.com-comments.

ottacke1991 avatar ottacke1991 commented on May 28, 2024

Dmitry, thank you for this post. I think that will be a great thing if you write more about javascript and functional programing in your new posts. Thanks!

from dmitripavlutin.com-comments.

devolasvegas avatar devolasvegas commented on May 28, 2024

Thanks, Dimitri, for your thorough and accessible explanations. I now feel much more confident that I can explain and use closures and currying. Scope and lexical scope are definitely the key to understanding these concepts. This is the first of several articles about closures which I have read that includes this and it made all the difference.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Thanks, Dimitri, for your thorough and accessible explanations. I now feel much more confident that I can explain and use closures and currying. Scope and lexical scope are definitely the key to understanding these concepts. This is the first of several articles about closures which I have read that includes this and it made all the difference.

That's great @devolasvegas!

from dmitripavlutin.com-comments.

mohanzeal avatar mohanzeal commented on May 28, 2024

thanks a lot Dmitri for this great article. I am preparing for an interview.. your article is really helping me.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

thanks a lot Dmitri for this great article. I am preparing for an interview.. your article is really helping me.

Good luck in your interview @mohanzeal! I hope my post will help you.

from dmitripavlutin.com-comments.

Kreynar avatar Kreynar commented on May 28, 2024

"Now innerFunc() is executed outside of its lexical scope"
Is it really? It's executed in global scope. And global scope is inside all functions' lexical scope, isn't that correct?

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

"Now innerFunc() is executed outside of its lexical scope" Is it really? It's executed in global scope. And global scope is inside all functions' lexical scope, isn't that correct?

Thanks @Kreynar and @Steph638 for finding the problem that innerFunc() executes inside of the global scope (i.e. its lexical scope). The post has been fixed in this regards.

from dmitripavlutin.com-comments.

bilalyaqoob avatar bilalyaqoob commented on May 28, 2024

amazing content, learned alot from it.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

amazing content, learned alot from it.

Glad you find it useful @bilalyaqoob!

from dmitripavlutin.com-comments.

jaynaras avatar jaynaras commented on May 28, 2024

Excellent. Now I understood exactly what closure means. Thanks a lot.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Excellent. Now I understood exactly what closure means. Thanks a lot.

You're welcome @jaynaras!

from dmitripavlutin.com-comments.

awadhesh31st avatar awadhesh31st commented on May 28, 2024

That's a very useful article about closures.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

That's a very useful article about closures.

Thanks @awadhesh31st! Glad you like it. :)

from dmitripavlutin.com-comments.

kwu-work avatar kwu-work commented on May 28, 2024

What a clear and concise explanation! thank you.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

What a clear and concise explanation! thank you.

You're welcome @kwu-work!

from dmitripavlutin.com-comments.

heraldjose10 avatar heraldjose10 commented on May 28, 2024

Thank you. This is very insightful.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Thank you. This is very insightful.

Thanks @heraldjose10!

from dmitripavlutin.com-comments.

BuddyChi avatar BuddyChi commented on May 28, 2024

Thank you ! This is a very useful article.
" The closure is a function that accesses its lexical scope even executed outside of its lexical scope."
But how setTimeout function execute outside of its lexical scope?
Thanks for your explanation.

from dmitripavlutin.com-comments.

varadan13 avatar varadan13 commented on May 28, 2024

hey man thank you for the wonderful set of articles.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

@varadan13 You're welcome!

from dmitripavlutin.com-comments.

danyn avatar danyn commented on May 28, 2024

I really appreciate how clear the topic is in your work. I also learned how currying works and your example made that very clear in a small amount of space. Good explanations of closures, lexical scope, and currying while maintaining a simple enough context for examples!

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

@danyn Glad you like it 😄 .

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

@xuxuewen Thanks! Sure, feel free to translate. 👍

from dmitripavlutin.com-comments.

shankar7042 avatar shankar7042 commented on May 28, 2024

Can you please explain how the following code works? 🙏🙏

for(var i = 0; i < 3; i++) {
const log = () => {
console.log(i)
}
setTimeout(log, 1000)
}

This code prints: 3, 3, 3 to the console but, As soon as, I change the keyword var to let the same code is printing 0, 1, 2 on to the console.

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Can you please explain how the following code works? 🙏🙏

Hi @shankar7042! Please see a detailed explanation here.

from dmitripavlutin.com-comments.

AmirovQodir avatar AmirovQodir commented on May 28, 2024

Thank you for your explanation. It's really helpful

from dmitripavlutin.com-comments.

panzerdp avatar panzerdp commented on May 28, 2024

Thank you for your explanation. It's really helpful

@AmirovQodir You're welcome. 👍

from dmitripavlutin.com-comments.

olhacodes avatar olhacodes commented on May 28, 2024

Thanks a lot! Really helpful. But stack.length = 0; isn't does nothing it deletes all values inside the array.

from dmitripavlutin.com-comments.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.