JavaScript Lingo: Variables & camelCase

We are going to cover what constitutes a variable, and the reasoning behind camelCase.

A variable, also referred to as 'var', is the name or placeholder for a boolean, string, number, or other piece of static information.

You can use Google Dev Tools to inspect the Free Code Camp home page and look for some variables.

You 'declare' variables the first time with 'var' in front of it, but those can be referenced later in your script.

camelCase is the way that JavaScript pushes words together and still keeps them legible. The first letter of the first word is lowercase, along with the remainder of the word, but the first letter of every consecutive word is capitalized. There are no spaces. Examples: brianaLovesHerPets, bestFoodIsCheese, and codeIsWorthLearning.

When you name variables, utilize camelCase. Also try to keep the names descriptive and short so that others (and yourself!) can tell what that variable is referring to just by the name.

接下来我们会讲到 变量 和 骆驼拼写法




骆驼拼写法是 JavaScript 拼写字符的一种方式,它有很高的易读性。 单词的第一个字母是小写的, 单词中其他的字母也是, 但是每个连续单词的第一个字母都是大写的。中间灭有空格。 例: brianaLovesHerPets, bestFoodIsCheese, and codeIsWorthLearning.

当你明明变量的时候, 使用 骆驼拼写法。 并且让变量的命名尽可能的具有描述性和尽可能短,这样别人(还有你)才可以根据名字来判断一个变量是什么