Coding in JS - Lesson 2

by onejdc

HTML

<h1 class='center'>Lesson 2 - Javascript Arrays and Objects</h1>

CSS

html, body { margin: 0; padding: 0; background-color:black;}
h1 { display:block;  color: rgb(0,228,150);text-align:center;}

.center { display:flex;justify-content:center;align-items:center; height:90vh;}

JavaScript

//======================================================================
// 								Introduction to Javascript, Part 2
//======================================================================

/*
	Recall that in Part 1, we covered the following topics:
	- Comments
		- inline
		- multiline
	- Whitespace
	- Statements
	- Code Blocks
	- Variables
		- Types
			- Boolean, null, undefined, Number, String, Array, Object
		- Names
		-	Scope
	- Operators
		- Assignment:	=
		- Math: 			+, -, *, /, %, ^, ++, --
		- Comparison:	>, >=, <, <=, ==, ===
		- Logic:			&&, ||, !
	- Control Structures
		- if statements
		- for loop
		- while loop
	- Functions
		- Arguments
		- Calling
		- Return Values
*/

/*
	Now in Part 2, we will go a bit deeper into your understanding of two specific
	variable types: Arrays and Objects. Because of the way the Javascript engine
	runs behind the scenes, there are some inherent opportunities for confusion.
	I will do my best to address these as they come up.
*/

//--------------------------------------------------------------------
// Arrrays
//--------------------------------------------------------------------

/*
	Arrays are wonderful containers for storing collections of data. They are the most
	common data structure available. Arrays in Javascript	are mutable. That means that 
	they can be changed.
	
	- The items in an array are positional.
	- Arrays can hold any type of data/variable
		- this includes mixed sets. the first 3 items in your array could be a boolean,
			followed by two Numbers, and then even another array!
	- Each position can be referred to by its INDEX.
	- !!!!! Array indexes start at ZERO !!!!!
	
	e.g.
*/

	// INDEX:        0        1            2             3         4        5       6
	let fruits =  ["apple", "banana", "strawberrry", 'broccoli', "kiwi", "peach", "steak"];
	let prices = [ 0.89  ,   0.59  ,     2.29     ,     1.15  ,   1.89,   1.11,    8.99 ];
	
	// Print the item at index 3
	console.log( fruits[3] ); //...