3.1 KiB
3.1 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
56533eb9ac21ba0edf2244ab | Understanding Case Sensitivity in Variables | 1 |
Description
MYVAR
is not the same as MyVar
nor myvar
. It is possible to have multiple distinct variables with the same name but different casing. It is strongly recommended that for the sake of clarity, you do not use this language feature.
Best Practice
Write variable names in JavaScript in camelCase. In camelCase, multi-word variable names have the first word in lowercase and the first letter of each subsequent word is capitalized. Examples:var someVariable;
var anotherVariableName;
var thisVariableNameIsSoLong;
Instructions
Do not create any new variables.
Tests
tests:
- text: <code>studlyCapVar</code> is defined and has a value of <code>10</code>
testString: 'assert(typeof studlyCapVar !== "undefined" && studlyCapVar === 10, "<code>studlyCapVar</code> is defined and has a value of <code>10</code>");'
- text: <code>properCamelCase</code> is defined and has a value of <code>"A String"</code>
testString: 'assert(typeof properCamelCase !== "undefined" && properCamelCase === "A String", "<code>properCamelCase</code> is defined and has a value of <code>"A String"</code>");'
- text: <code>titleCaseOver</code> is defined and has a value of <code>9000</code>
testString: 'assert(typeof titleCaseOver !== "undefined" && titleCaseOver === 9000, "<code>titleCaseOver</code> is defined and has a value of <code>9000</code>");'
- text: <code>studlyCapVar</code> should use camelCase in both declaration and assignment sections.
testString: 'assert(code.match(/studlyCapVar/g).length === 2, "<code>studlyCapVar</code> should use camelCase in both declaration and assignment sections.");'
- text: <code>properCamelCase</code> should use camelCase in both declaration and assignment sections.
testString: 'assert(code.match(/properCamelCase/g).length === 2, "<code>properCamelCase</code> should use camelCase in both declaration and assignment sections.");'
- text: <code>titleCaseOver</code> should use camelCase in both declaration and assignment sections.
testString: 'assert(code.match(/titleCaseOver/g).length === 2, "<code>titleCaseOver</code> should use camelCase in both declaration and assignment sections.");'
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;