One Pager Cheat Sheet
- This lesson explains how to use
variablesand theirassignmentto store data in a programming language. - A variable
acan be assigned a data value using theassignment operatorequal sign(=), and for the duration of the program, it will correspond to that value unless reassigned. - Variables in JavaScript can be declared with the
varkeyword, and stored in memory with a value which can be displayed withconsole.log(). Additionally,letandconstare also used to declare variables in order to avoidglobal variablemodification. - Using
letandconstinstead ofvaris a good way to prevent confusing variables in larger codebases because they are block-scoped and can only be used within specific{and}symbols. - Carefully following rules such as variable names only containing alphabetical letters, digits or underscore symbols, being aware of case-sensitivity and not using language-specific keywords will help to create variables correctly and avoid errors.
- No, this code snippet is not valid for declaring a variable in JavaScript, as the syntax
var <variable name>(for example,var myVariable) is not followed. - No valid JavaScript variable name can contain characters, so
var words: "Hello World!"is invalid, whereas_nameis valid. - Variables can be reassigned in JavaScript by assigning a new value without using
var, resulting in the change of their value. - Different types of variables can be used to perform different kinds of operations, such as mathematical operations for numbers and concatenation for strings.
- The value of
ahas been changed from "Hello" to "World". - The code
concatenatesthestringsstored infirstNameandlastNamein to a newvariablename, which is thenconsole.logged to outputAnnaGreen. - Creating variables with meaningful names is an important step in the programming process to avoid
confusionof which variables is used to store what value.

