Skip to content

Instantly share code, notes, and snippets.

@monstaro
Last active July 29, 2019 22:31
Show Gist options
  • Save monstaro/c36e2385be240f96c007204270f491e0 to your computer and use it in GitHub Desktop.
Save monstaro/c36e2385be240f96c007204270f491e0 to your computer and use it in GitHub Desktop.
Mod 0 Capstone

New comment for each day of the capstone

@monstaro
Copy link
Author

monstaro commented Jul 29, 2019

To declare a variable, type the keyword var and then whatever variable you are using, for example, quantity
The equals sign is an assignment operator. It assigns a value to the variable, for example, if your variable name and value is a quantity of 3, you could type quantity = 3; and the equals sign assigns the value to the name.

Strings: Strings consist of letters and other characters such as symbols & punctuation. They are enclosed in a pair of single or double quotes, and are usually used to add new content into a page.
Numbers: Probably the most self-explanatory. This data type stores numbers, including positive and negative numbers, as well as fractional numbers/decimals.
Booleans: Booleans return one of two values: true or false. Possibly the most complex of the three data types (at least at first) it can help return results to a user such as color preference of a car or location information.

What are the six rules for naming variables? What are a few JavaScript reserved words that you should avoid using for variable names?

  • The name cannot start with a number. It must begin with a letter, dollar $ign, or under_score.
  • The rest of the name can contain anything listed above, with the addition of numbers as well. Do not use a dash - or a period . in a variable name.
  • Cannot used a reserved word or keyword. There are full lists available for reserved words in JavaScript. An example would be var because it is already a keyword, so you cannot name a variable a keyword that already exists.
  • Variables are case sensitive. Always use consist casing when naming variables, and it is good practice not to create two variables with the same word but different casing.
  • Use a relavent name when naming variables. For example, hairColor eyeColor instead of characteristicA and characteristicB
  • If the variable name is more than one word, you want to keep the first word entirely lowercase, and for every following word, capitalize the first letter. forExampleThis. This is called camelcase. You can also use underscores, but not dashes.

How can an array be useful when dealing with multiple related values? How do you access/change a value in an array?

Arrays are useful when you are creating a list and you don't know how many items it will contain. This way, you don't have to create enough variables for a long list. To access a value in an array, you type array_name[array_value] or put into context, colors[2] using the example from the book. To change that value, simply add an equals sign and new value in quotes. The full statement would look like this: `array_name[array_value] = 'new value'

What is the difference between an expression and a statement?
A statement simply is a line of instructions, like `array_name[array_value] = 'new value'
An expression can either assign a value to a variable, or use multiple variables to return a single variable.
Basically, an expression is meant to return a single value from one or multiple values, but a statement is more like an instruction.

Three types of operators covered in Chapter 2 are assignment, arithmetic and string operators.
Assignment Operators assign a value to a variable, ex. size = 'large'
Arithmetic Operators perform basic math. ex. hoursPerMonth = 40 * 4;
String Operators can combine two strings 'Today is' + 'September 24th';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment