Defining Variables Properly

The getNiceDate() function in Figure 6-12 calls the year variable the_year. However, when you look at how the Y2K() function appears in ❸, you'll see that it calls whatever passes into it the_date. Since we're calling Y2K(the_year), JavaScript looks up the value of the_year and then sends that value to the Y2K() function. The Y2K() function stores that value in the variable the_date. In other words, the functions getNiceDate() and Y2K() have two different names for the same value. It's as if the functions are different countries where people speak different languages. If you try to talk about the_year inside the Y2K() function, it won't know what you're saying, and you'll get an error. Figure 6-13 shows you a graphical ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.