- See more at: http://blogtimenow.com/blogging/automatically-redirect-blogger-blog-another-blog-website/#sthash.YsVbCxL0.dpuf Journey to Becoming a Web Developer: Lexical Scoping

Sunday, February 2, 2014

Lexical Scoping


In the example above I was able to find all of the even numbers in an array using lexical scoping and the .filter method.  Because I defined the getNumbers function inside of the parent function getEvenNumbers the child function getNumbers knows about numbersArray.  So when I call the .filter method it will iterate through each element in the array passed to numberArray then pass  it to the callback function getNumbers which checks to see if each element is divisible by 2.  .filter will return the results in a new array.


No comments:

Post a Comment