Friday, April 10, 2015

Do not declare function and variable with the same name in same scope

In Javascript functions and variables share same namespace  and that is why this code will break

 

<script>

        function ThisIsAFunction(n) {

            alert(n);

        };

 

        var ThisIsAFunction = 'India';

 

        alert('abount to execute');

 

        ThisIsAFunction('Hello');

    </script>

 

Basically 1st statement in code is similar to

var ThisIsAFunction  = function ThisIsAFunction(n) { alert(n); };

 

Or

 

var ThisIsAFunction = = function (n) { alert(n); };

 

and this will collide even inside a closure as closure will be scope rather than global.

10 comments:

Nandhini said...

Pretty section of content. I simply stumbled upon your site and in accession capital to say that I get actually loved to account your blog posts.
Security Services in Chennai

Abiya Carol said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

AWS Training in Chennai

Mahalyasree said...

This is a very interesting web page and I have enjoyed reading many of the articles and posts contained on the website, keep up the good work and hope to read some more interesting content in the future.
Office Interiors in Chennai
Interior Decorators in Chennai

Sowmiya said...

Really Good blog post.provided a helpful information.I hope that you will post more updates like this.
MSBI Training in Chennai

Alya Kannan said...

very very amazing explaintion....many things gather about yourself...yes realy i enjoy it
SEO Company in India

Abitha Chetna said...

This blog is having the general information.Got a creative work and this is very different one.We have to develop our creativity mind.This blog helps for this. Thank you for this blog.This is very interesting and useful.

Bigdata Training in Chennai

Search Optimization said...

Content is very clear and easily explained it is very interesting as well. I hope you post again soon.

BIGDATA Training in Chennai

Atom Steels said...

The Interior Designer is a plans, researches, coordinates, and manages the projects. Interior design is a multifaceted profession that includes conceptual development, space planning, site inspections, programming, research, communicating with the stakeholders of a project, construction management, and execution of the design.

Interior Designers in OMR

Kalai chellam said...

Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

Restaurant in OMR
Apartments in OMR
Villas in OMR
Resorts in OMR

justin vijay said...

Following logical rules such as “if/then” rules, Making calculations, Extracting data from documents, Inputting data to forms, Extracting and reformatting data into reports or dashboards, Merging data from multiple sources and Copying and pasting data are some of the Data Processing models.
Robotic Process Automation training in Chennai