WHAT'S NEW?
Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts
Scope is an important aspect in programming. This scope concept is quite different and challenging in JavaScript. This is more in case of variables because of the variable hosting concept.

Keyword - 'var' makes variables available at global if its not bound inside a function and when inside a function, it is available as a scope variable all throughout that function.

On the other hand, 'let' keyword restricts the variable similar to how the scope of variables in with C# or Java. This brings in the most needed advantage and functionality that has been making developers get nightmares for because of variable hoisting.






JS functions are objects that are a created as a block to perform a specific action.

If we pass an object to the JS function and modify the object's property, it is reflected at the global level.
Where as if we try to modify the object itself, it is modified with in the scope of the function and not outside of it (i.e., at the global level)
Here is the example for it.

If you are coming from Java/C# background, I am sure that you all know about method overloading as one of the OOPS concepts. So, let us see how JS works with method overloading.
Let us try to understand if JS support method overloading or not.

Now, let us send 3 parameters/arguments to the method.
Now, let us create another method with the same name "add" that takes 3 parameters/arguments.
Thus we can conclude that JS does not allow us to have method overloading. JS complier considers the last method in the line of execution with the same name as the method to be executed.
We all have seen variables in JS  that throw an undefined primitive type when they are not assigned any value in Series 1 of JS.
Now, let us see what happens when we add a Undefined primitive type to some value.

A look at the way the Pass by value and Pass by reference work in JavaScript.
I was teaching my cousin JS in his summer vacation. I will post those basic JS details that i taught him here on my blog in a series