we only pass one argument to CreateGreeting (i.e is the greeting ‘good morning’)
but when we pass the other argument ‘xyz’ it becomes name, how did this happen?
I did not get the functioning behind the code
Here let g1 = CreateGreeter(‘Good Morning’) you are not passing ‘Good Morning’ to g1 you are passing it to CreateGreeter() function so it is treated as a greeting.
But when you pass ‘xyz’ to g1() it is passed to function greet() because CreateGreeter returns greet so g1 becomes greet() function and xyz becomes name.
i tried doing the same thing with diffrent names but i got an error https://ide.codingblocks.com/s/411123
I am not getting error both are printing good morning
i am not getting the xyz part https://ide.codingblocks.com/s/411122, what is the concept that i am lacking due to which i am not able to understand the code
You are lacking basic concept of OOPS:
In let g1 = CreateGreeter(‘good morning’)
You are passing parameter in CreateGreeter that is greeting and it will return a function greet that will get stored in g1.
In next line you are passing in g1(‘xyz’) which means it is greet(‘xyz’)
This is quite basic concept in OOPS