2.5 KiB
2.5 KiB
id, challengeType, videoUrl, forumTopicId, localeTitle
id | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244ab | 1 | https://scrimba.com/c/cd6GDcD | 18334 | 了解变量名区分大小写 |
Description
MYVAR
与MyVar
和myvar
是截然不同的变量。这有可能导致出现多个相似名字的的变量。所以强烈地建议你,为了保持代码清晰不要使用这一特性。
最佳实践
使用驼峰命名法来书写一个 Javascript 变量,在驼峰命名法中,变量名的第一个单词的首写字母小写,后面的单词的第一个字母大写。 示例:var someVariable;
var anotherVariableName;
var thisVariableNameIsSoLong;
Instructions
Tests
tests:
- text: <code>studlyCapVar</code>应该被定义并且值为<code>10</code>。
testString: assert(typeof studlyCapVar !== 'undefined' && studlyCapVar === 10);
- text: <code>properCamelCase</code>应该被定义并且值为<code>"A String"</code>。
testString: assert(typeof properCamelCase !== 'undefined' && properCamelCase === "A String");
- text: <code>titleCaseOver</code>应该被定义并且值为<code>9000</code>。
testString: assert(typeof titleCaseOver !== 'undefined' && titleCaseOver === 9000);
- text: <code>studlyCapVar</code>在声明和赋值时都应该使用驼峰命名法。
testString: assert(code.match(/studlyCapVar/g).length === 2);
- text: <code>properCamelCase</code> 在声明和赋值时都应该使用驼峰命名法。
testString: assert(code.match(/properCamelCase/g).length === 2);
- text: <code>titleCaseOver</code> 在声明和赋值时都应该使用驼峰命名法。
testString: assert(code.match(/titleCaseOver/g).length === 2);
Challenge Seed
// Declarations
var StUdLyCapVaR;
var properCamelCase;
var TitleCaseOver;
// Assignments
STUDLYCAPVAR = 10;
PRoperCAmelCAse = "A String";
tITLEcASEoVER = 9000;
Solution
var studlyCapVar;
var properCamelCase;
var titleCaseOver;
studlyCapVar = 10;
properCamelCase = "A String";
titleCaseOver = 9000;