Objects
Objects are a collection of properties. My dog is an object and he holds many properties such as breed,
name, age, etc. The property values differ from object to object or more specifically in my case, dog to
dog. Each variable contains an object that contains values. Objects can hold a lot of related
information. Example: my dog, which is the object has a key of ‘name’. His name, which is the value, is
“Groot”.
Example:
- Let dog = {
- Name: “Groot”,
- Breed: “Great Dane”,
- Age: 2,
- Weight: 150lbs,
- Good Boy: True
- }
Arrays
Arrays are a type of variable. They can hold many values under a single name. An array's length can
change at any time and its data can be stored at non-contiguous locations. Arrays are usually in
brackets [ ] and are separated by commas. The index of an array starts at 0 and continues upward.
Example:
- Let dogBreeds = [“Great Dane”, “Newfoundland”, “Beagle”, “Corgi”];
- Console.log(dogBreeds[0]) ↢ this will spit out the dog breed Great Dane because it is in the 0
index.
For Loops
A For Loop runs through a block of code a number of times which loops through the properties of an
object. If you want to run a code over and over again, then a For Loop is your answer. It changes the
value of the code you inputted. For loops are divided into three statements. The first sets a variable
before the loop starts (i = 1). The second defines the condition for the loop to run (i < 9) and the
third increases the value each time (i++). With the example below, the answer will come out as 1, 2,
3, 4, 5, 6, 7, 8, 9.
Example:
- For (i = 1; i < 9; i++) {
- console.log(i);
- }