Mark As Completed Discussion

One Pager Cheat Sheet

  • This lesson explains how to use variables and their assignment to store data in a programming language.
  • A variable a can be assigned a data value using the assignment operator equal sign (=), and for the duration of the program, it will correspond to that value unless reassigned.
  • Variables in JavaScript can be declared with the var keyword, and stored in memory with a value which can be displayed with console.log(). Additionally, let and const are also used to declare variables in order to avoid global variable modification.
  • Using let and const instead of var is 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 _name is 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 a has been changed from "Hello" to "World".
  • The code concatenates the strings stored in firstName and lastName in to a new variable name, which is then console.logged to output AnnaGreen.
  • Creating variables with meaningful names is an important step in the programming process to avoid confusion of which variables is used to store what value.