Many popular frameworks, such as JQuery, use dollar signs in their variable names to denote specialized properties and methods for that framework. Since that de facto convention has become more common, most programmers don’t use dollar signs in their own code as often; this avoids confusion when using frameworks.
Underscores give useful information through variable names in two different contexts. Since variable names cannot contain spaces, underscores can separate words in variable names to make code clearer. Many programmers also start variable names with underscores if those variables shouldn’t be directly changed.
var _secondsPerYear = ( 365 * 24 * 60 * 60 ) ; // a constant value
undefined. Remember that
undefined is not the same data type as
var keyword. The
const keywords first appeared in ES2015.
var myVar1; let myVar2; const myVar3 = 1;
let keywords allow you to declare a variable without assigning it to a value because both keywords create variables that a program may update later. In contrast, you must assign a value to any variable that uses the
const keyword; this keyword creates a constant value that cannot be changed once the variable has been defined.
It is possible to create and define multiple variables at the same time. To do this, separate variables with commas. Variable definitions can span multiple lines as well; the following two variable definition groups are equivalent.
let company = "Udacity", author = "JSRC", blog = "variables"; let company = "Udacity", author = "JSRC", blog = "variables";