Object
Array
functions ES5
{}
var box = {};
var box = {};
box.material = "cardboard";
When are some other times you have seen dots in JS?
var box = {"material" : "cardboard"}
var box = {};
box.material = "cardboard";
box.material; //??
var box = {"material" : "cardboard"}
var box = {};
box.material = "cardboard";
var cb = box.material;
var box = {"material" : "cardboard"}
box = {"material" : "cardboard"}
var box = {};
box.material = "cardboard";
var cb = box.material;
cb; //??
box.material = "titanium";
cb; //??
box = {"material" : "titanium"}
cb = "cardboard"
var box = {};
box.material = "cardboard";
box.material; //"cardboard"
box.size; //??
var box = {"material" : "cardboard"}
var box = {};
box["material"] = "cardboard";
box.material; //??
var box = {"material" : "cardboard"}
var box = {};
box["material"] = "cardboard";
box["material"]; //??
var box = {"material" : "cardboard"}
var box = {};
box["material"] = "cardboard";
var key = "material";
box[key]; //??
var box = {};
box["material"] = "cardboard";
var func = function(){
return "material";
};
box[func()]; //??
var box = {};
box['material'] = "cardboard";
var key = 'material';
box['key']; //??
var box = {};
box['material'] = "cardboard";
var key = 'material';
box['key']; //undefined
box.key; //??
var box = {};
box['material'] = "cardboard";
var key = 'material';
box['key']; //undefined
box.key; //undefined
var box = {};
box['material'] = "cardboard";
var key = 'material';
box['key']; //undefined
box.key; //undefined
box[key]; //??
var box = {};
box['material'] = "cardboard";
var key = 'material';
box['key']; //undefined
box.key; //undefined
box[key]; //"cardboard"
var box = {};
box['material'] = "cardboard";
box[0] = 'meow';
box['^&*'] = "testing 123";
var test = box['^&*'];
box = {"material" : "cardboard", "0" : "meow", "^&*" : "testing 123" }
DOTS
strings
Brackets
strings"
"quotes required
weird characters"
variables
numbers
numbers
quotations
weird characters
expressions
expressions
var box = {};
box["material"] = "cardboard";
box["size"] = {
"height": 2,
"width": 80
};
box.area = function(){
return box.size.height * box.size.width;
};
var box = {};
box['size'] = 9;
box['~/ [."4'] = 'meow';
box['size']; // 9
box['~/ [."4']; // 'meow'
var box = { box['size'] = 9; box['~/ [."4'] = 'meow';
};box['size']; // 9 box['~/ [."4']; // 'meow'
var box = {
};box['size']= 9;box['~/ [."4']= 'meow';box['size']; // 9 box['~/ [."4']; // 'meow'
var box = { 'size' = 9; '~/ [."4' = 'meow';
};box['size']; // 9 box['~/ [."4']; // 'meow'
var box = { 'size' : 9, '~/ [."4' : 'meow';
};box['size']; // 9 box['~/ [."4']; // 'meow'
var box = { 'size' : 9, '~/ [."4' : 'meow'
};box['size']; // 9 box['~/ [."4']; // 'meow'
var box = {};
box['material'] = "cardboard";
box[0] = 'meow';
box['^&*'] = "testing 123";
for(var key in box){
console.log(key); //??
}
var box = {};
box['material'] = "cardboard";
box[0] = 'meow';
box['^&*'] = "testing 123";
for(var key in box){
console.log(box[key]); //??
}
[]
var box = [];
box[0] = true;
box[1] = 'meow';
box.push({'hello' : 'goodbye'});
var i = 0;
box[i]; // ??
box[1];
box.pop() //??
[true, 'meow', {'hello' : 'goodbye'}]
index# 0 1 2
{0 : 'meow', 'size' : 9 }
var box = {};
box['size'] = 9;
box['0'] = 'meow';
box['size']; // 9
box[0]; // 'meow'
var box = [];
box['size'] = 9;
box['0'] = 'meow';
box['size']; // ??
box[0]; // ??
['meow']
index # 0
{0 : 'meow', 'size' : 9 }
var box = [];
box['size'] = 9;
box['0'] = 'meow';
box.size; // ??
box[0]; // ??
['meow']
index # 0
{0 : 'meow', 'size' : 9 }
var box = [];
box['size'] = 9;
box['0'] = 'meow';
box.size; // ??
box.0; // ??
['meow']
index # 0
{0 : 'meow', 'size' : 9 }
var box = [];
box['size'] = 9;
box['0'] = 'meow';
for(var k in box){
console.log(k); // ??
}
['meow']
index # 0
{0 : 'meow', 'size' : 9 }
var box = [];
box['size'] = 9;
box['0'] = 'meow';
for(var k in box){
console.log(box.k); // ??
}
['meow']
index # 0
{0 : 'meow', 'size' : 9 }
var box = [];
box['size'] = 9;
box['0'] = 'meow';
for(var k in box){
console.log(box[k]); //??
}
['meow']
index # 0
{0 : 'meow', 'size' : 9 }
var box = [];
box['size'] = 9;
box['0'] = 'meow';
box.push('Whoohoo!');
for(var k in box){
console.log(box[k]);
}
for(var i = 0; i < box.length; i++){
console.log(i); //??
}
['meow', 'Whoohooo!']
index # 0 1
{0 : 'meow', 1 : 'Whoohooo!', 'size' : 9 }
var box = [];
box['size'] = 9;
box['0'] = 'meow';
box.push('Whoohoo!');
for(var i = 0; i < box.length; i++){
console.log(box.i); //??
}
['meow', 'Whoohooo!']
index # 0 1
{0 : 'meow', 1 : 'Whoohooo!', 'size' : 9 }
var box = [];
box['size'] = 9;
box['0'] = 'meow';
box.push('Whoohoo!');
for(var i = 0; i < box.length; i++){
console.log(box[i]); //??
}
['meow', 'Whoohooo!']
index # 0 1
{0 : 'meow', 1 : 'Whoohooo!', 'size' : 9 }
var box = [];
box['size'] = true;
box['0'] = 'meow';
box.length; //??
['meow']
index # 0
{0 : 'meow', 'size' : 9 }
var box = [];
box['0'] = 'meow';
box[3] = {'babyBox': true};
box['length']; //??
var box = [];
box['0'] = 'meow';
box[3] = {'babyBox': true};
box[length]; //??
var box = [];
box['0'] = 'meow';
box[1] = 'Whoohooo!';
box[3] = {'babyBox': true};
box[box.length]; //??
var box = [];
box['size'] = 9;
box['0'] = 'meow';
box[1] = 'Whoohooo!';
box[box.length - 1]; //??
['meow', 'Whoohooo!']
index # 0 1
{0 : 'meow', 1 : 'Whoohooo!', 'size' : 9 }
var box = [];
box['0'] = 'meow';
box[1] = 'Whoohooo!';
box[box.length - 1]; //??
['meow', 'Whoohooo!']
index # 0 1
{0 : 'meow', 1: 'Whoohooo!'}
var box = {};
box.innerBox = {};
var box = {"innerBox" : {}}
var box = {};
box['innerBox'] = {};
var box = {"innerBox" : {}}
var box = {};
box['innerBox'] = {};
box['innerBox']['full'] = true;
var box = {"innerBox" : { full: true } }
var box = {};
box['innerBox'] = {};
box['innerBox'].full = true;
var box = {"innerBox" : { full: true } }
var box = {};
box.innerBox = {};
box.innerBox.full = true;
box.innerBox; //??
var box = {"innerBox" : { full: true } }
var box = {};
box.innerBox = {};
box.innerBox.full = true;
var myInnerBox = box.innerBox;
myInnerBox; //??
var box = {"innerBox" : { full: true } }
var box = {};
box.innerBox = {};
box.innerBox.babyBox = {};
box.innerBox['babyBox']; //??
box.innerBox['babyBox'].says = "What's up!?";
var box =
{"innerBox" : {
babyBox : {
says: "What's up!?"
}
}
}
var box = {};
box['innerBox'] = {};
box['innerBox'].full = true;
box[innerBox]['height'] = 10;
box[innerBox2].full = false;
What do you use to loop through an array?
What are some different methods of adding values to an array?
What are some special properties about arrays that are different from objects?
What are some ways to access values in your array?
When would you use an array over an object?
function(){}
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
$('body').hide();
myArr.forEach(function(val){ console.log(val);});
$('button').on('click', function(){
console.log('Don\'t press my buttons!');
});
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
$('body').hide();
myArr.forEach(function(val){ console.log(val);});
$('button').on('click', function(){
console.log('Don\'t press my buttons!');
});
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
$('body').hide();
myArr.forEach(function(val){ console.log(val);});
$('button').on('click', function(){
console.log('Don\'t press my buttons!');
});
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
$('body').hide();
myArr.forEach(function(val){ console.log(val);});
$('button').on('click', function(){
console.log('Don\'t press my buttons!');
});
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
$('body').hide();
myArr.forEach(function(val){ console.log(val);});
$('button').on('click', function(){
console.log('Don\'t press my buttons!');
});
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
$('body').hide();
myArr.forEach(function(val){ console.log(val);});
$('button').on('click', function(){
console.log('Don\'t press my buttons!');
});
var add = function(a, b){
return a + b;
};
add(3, 4, 5); // ??
add(4, 10, 3); //13?
var add = function(a, b){
console.log(arguments); //logs [3,10,5]
return a + b;
};
add(3, 10, 5); //13
var add = function(a, b){
console.log(arguments); //logs [3,10,5]
return a + b;
};
add(3, 10, 5); //18??
var add = function(a, b){
arguments.slice(0,1) //ERROR!!
return a + b;
};
add(3, 10, 5);
var add = function(a, b){
return a + b;
};
add.example = 'testing 123!';
function AnimalMaker(name) {
return {
speak: function () {
console.log("my name is ", name);
}
};
};
var animalNames = ['Sheep', 'Liger', 'Big Bird'];
function AnimalMaker(name) {
return {
speak: function () {
console.log("my name is ", name);
}
};
};
var animalNames = ['Sheep', 'Liger', 'Big Bird'];
var farm = [];
function AnimalMaker(name) {
return {
speak: function () {
console.log("my name is ", name);
}
};
};
var animalNames = ['Sheep', 'Liger', 'Big Bird'];
var farm = [];
for(var i = 0; i < animalNames.length; i++){
var animal = AnimalMaker(animalNames[i])
farm.push(animal);
}
function AnimalMaker(name) {
return {
speak: function () {
console.log("my name is ", name);
}
};
};
var animalNames = ['', '', ''];
var farm = [];
for(var i = 0; i < animalNames.length; i++){
farm.push(AnimalMaker(animalNames[i]));
//prev 2 lines condensed onto one
}
function AnimalMaker(name) {
return {
speak: function () {
console.log("my name is ", name);
}
};
};
var animalNames = ['Sheep', 'Liger', 'Big Bird'];
var farm = [];
for(var i = 0; i < animalNames.length; i++){
farm.push(AnimalMaker(animalNames[i]));
}
for(var j = 0; j < farm.length; j++){
farm[j].speak()
}
var func = function(){
var local = true;
};
console.log(local);
var x = 'global!';
var x = 'global!';
//inside a function
function encapsulate(){
z = 'global here, too!';
}
var x = 'global!';
//inside a function
function encapsulate(){
z = 'global here, too!';
window.y = 'also global!';
}
var g = 'global';
function blender(fruit) {
var b = fruit;
var y = 'yogurt';
function bs() {
alert( b + ' and ' + y + ' makes ' + b + ' swirl');
}
bs();
}
blender('blueberry');
var g = 'global';
function blender(fruit) {
var b = fruit;
var y = 'yogurt';
function bs() {
alert( b + ' and ' + y + ' makes ' + b + ' swirl');
}
bs();
}
blender('blueberry');
var g = "global";
function go() {
var l = "local";
var g = "in here!";
alert(g + " inside go");
}
go();
alert(g + " outside go");
var inBlock = false;
for(var i = 0; i < 5; i++){
var inBlock = true;
};
if(inBlock){
console.log('Is there block scope? ' + !inBlock);
}