New comment for each day of the capstone
Last active
July 29, 2019 22:31
-
-
Save monstaro/c36e2385be240f96c007204270f491e0 to your computer and use it in GitHub Desktop.
Mod 0 Capstone
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
var
because it is already a keyword, so you cannot name a variable a keyword that already exists.hairColor
eyeColor
instead ofcharacteristicA
andcharacteristicB
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';