Hello sir! I'm very glad about this video. But I have a question, why does "incBy2()" get called even before "incBy1()" finishes executing? Do both the lines execute at the same time thereby changing the value of "obj.increment" at the same time? Thanks a lot!
incBy2 doesn't get called before incBy1. The creation of that function gets called before we call the function creating incBy1. Because the increment by 2 function is created it changes the increment value to 2 because all variables are pointing to the same object. Does that help?
You could of at the end of the video, put the solution to fix the issue. I got what you was referring to, but you only pointed out the problem, not how to fix the problem.
There are several different things that can be done that can be covered in other tutorials. And to be fair the "problem" is caused by how we structure our code not necessarily a deficiency in JavaScript.
Hi. I have a question. In that example, why would someone write the line "obj.increment = val;" outside the return function. It seems weird enough, I mean, by doing so, that object value changes when the variable is declared unwantedly as you said and that causes the issue. Cloning solution aside, even if the case someone want the function variable change the value when excuted, it still looks kind of wrong because you can just write that line inside the return function so that the value changes only when the function designated to the variance get actually executed. Maybe you just made it up that way just for explaining it? I am assuming maybe there is a reason for that. Like, there is a similar javascript pattern that makes people write like that and there they makes this kind of mistakes.. or something like that. Just would like to know. Thanks.
It is quite common to do statements before you return a value from a function. So that wouldn't be out of the ordinary. And changing an object is not out of the ordinary either. But it is important to understand the implications. Those that subscribe the a functional approach would of course avoid making a change like that. Does that help?
@@AllThingsJavaScript I reviewed it again and I think I understand what was intended by that, in case of one want to make it reusable by simply calling the function with parameter I guess. It must have looked more familiar to me if I have more experience on the language. Thank you for the quick answer.
Watched it repeatedly several times, then come to know the creation of a function has that much impact.
this video does a good job in explaining "pass by reference".
@Conrad Maddox Yup, I have been using flixzone} for since december myself :)
Hello sir! I'm very glad about this video. But I have a question, why does "incBy2()" get called even before "incBy1()" finishes executing? Do both the lines execute at the same time thereby changing the value of "obj.increment" at the same time? Thanks a lot!
incBy2 doesn't get called before incBy1. The creation of that function gets called before we call the function creating incBy1. Because the increment by 2 function is created it changes the increment value to 2 because all variables are pointing to the same object. Does that help?
@@AllThingsJavaScript Hi. Thanks for the reply.
I understand it now. BTW, great tutorial :)
Great video and explanation !
You could of at the end of the video, put the solution to fix the issue. I got what you was referring to, but you only pointed out the problem, not how to fix the problem.
There are several different things that can be done that can be covered in other tutorials. And to be fair the "problem" is caused by how we structure our code not necessarily a deficiency in JavaScript.
Here is a link to a tutorial that provides a solution: ruclips.net/video/3ImrKR3OkHs/видео.html
Great ... very helpful !
This was really helpful thank sir.
Glad to hear that
Hi. I have a question. In that example, why would someone write the line "obj.increment = val;" outside the return function. It seems weird enough, I mean, by doing so, that object value changes when the variable is declared unwantedly as you said and that causes the issue. Cloning solution aside, even if the case someone want the function variable change the value when excuted, it still looks kind of wrong because you can just write that line inside the return function so that the value changes only when the function designated to the variance get actually executed. Maybe you just made it up that way just for explaining it?
I am assuming maybe there is a reason for that. Like, there is a similar javascript pattern that makes people write like that and there they makes this kind of mistakes.. or something like that. Just would like to know. Thanks.
It is quite common to do statements before you return a value from a function. So that wouldn't be out of the ordinary. And changing an object is not out of the ordinary either. But it is important to understand the implications. Those that subscribe the a functional approach would of course avoid making a change like that. Does that help?
@@AllThingsJavaScript I reviewed it again and I think I understand what was intended by that, in case of one want to make it reusable by simply calling the function with parameter I guess. It must have looked more familiar to me if I have more experience on the language. Thank you for the quick answer.
what the keyboard and switches do you use? CD nice sound
I hava a Microsoft ergonomic keyboard.