课程: JavaScript: Best Practices for Data

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Create descriptive variable names

Create descriptive variable names

- [Instructor] Brevity may be the soul of wit. But as my variable names here illustrate, writing code requires striking just the right balance between brevity and clarity. I have four variables here named A, B, X and Y. Looking at the first two, which are arrays, I can make a guess about what each contains, but I can't be sure. Inventory in a store's produce section, a couple shopping lists, ingredients for recipes. The final two are pretty much a complete mystery. Just numbers with no context. Now, when a parser is processing my JavaScript statements, it doesn't care about variable names at all. But for me and other humans working with the code, it's really helpful to understand what a variable is meant to contain. This lets me verify that the data matches the intent and also helps me understand the flow of my program as the variable's referenced in other statements. My first two variables are intended simply as lists.…

内容