Skip to content

Instantly share code, notes, and snippets.

@sranso
Last active January 4, 2016 04:09
Show Gist options
  • Save sranso/8566517 to your computer and use it in GitHub Desktop.
Save sranso/8566517 to your computer and use it in GitHub Desktop.
What does the following code print to the console?
var person = {
name: "Joe Camel",
age: 42,
status: "dead"
}
console.log(typeof person);
object
What does the following code print to the console?
var hat = {
size: "large",
color: "orange"
}
console.log(hat.size);
large
What does the following code print to the console.
var teddy_bear = {
texture: "fluffy"
}
console.log(teddy_bear["texture"]);
fluffy
What does the following code print to the console?
var fat_joe = {
crew: "Terror Squad"
}
fat_joe.crew = "something";
console.log(fat_joe.crew);
something
What does the following code print to the console?
var pen = {};
pen.ink = "blue";
console.log(pen.ink);
blue
What does the following code print to the console?
var walking_dead = {
topic: "zombie apocalypse"
}
console.log(walking_dead["main_character"]);
undefined // we queried a non-existing property from the obj
What does the following code print to the console?
var bottle = {
contents: function () { return "some fine bubbly" },
color: "green"
}
console.log(bottle.contents());
some fine bubbly
What does the following code print to the console?
var yao = {
self: function () { return this }
}
console.log(yao === yao.self());
true // self funciton returns this, which is yao
What does the following code print to the console?
var lebron = {
occupation: "basketball",
introduction: function () {
return "My name is LeBron and I play " + this.occupation
}
}
lebron.introduction();
My name is LeBron and I play basketball
What does the following code print to the console?
var square = {
side_length: 4,
area: function () {
return this.side_length * this.side_length;
}
}
console.log(square.area());
16
What does the following code print to the console?
var me = {
first_name: "Matthew",
last_name: "Powers",
full_name: function () {
return this.first_name + " " + this.last_name;
}
}
console.log(me.full_name());
Matthew Powers
What does the following code print to the console?
var mug = {
capacity: "10 fluid ounces",
customer_message: function (desired_size) {
if (desired_size > 10) { return "This mug is not large enough for you" };
}
}
console.log(customer_message(13));
customer_message not defined // it's w/in mug which we didnt call. if we wrote console.log(mug.customer_message(13)); it would work
What does the following code print to the console?
function global_function () { return "I can be called anywhere" };
var an_obj = {
something: global_function
}
console.log(an_obj.something());
I can be called anywhere
What does the following code print to the console?
var person = {
age: 32,
address: {
city: "New York",
state: "NY"
}
}
console.log(person.address.city);
New York
What does the following code print to the console?
var golf = {
type: "sport",
clubs: {
high_end: "taylor made",
low_end: "rusty basement clubs"
}
}
golf.clubs.high_end = "callaway";
console.log(golf.clubs.high_end);
callaway
What does the following code print to the console?
var ideal_scene = {
status: "chillin'",
location: "somewhere with good waves",
thoughts: "bling bling"
}
delete ideal_scene.thoughts
console.log(ideal_scene.thoughts);
undefined
Describe the value that the zombie variable is assigned to.
var zombie = new Object();
zombie is equal to {}. between those curly braces is where the properties of the variable would go.
What does the following code print to the console?
var game = { title: "tic tac toe" };
var same_game = { title: "tic tac toe" };
console.log(game === same_game );
false // bc they are not the same object
What does the following code print to the console?
var lyric = { lyric: "right now, aight" };
console.log(lyric === lyric);
because lyric IS equal to lyric. lyric.lyric is not the same as lyric, though.
What does the following code print to the console?
var ruff_ryders = {
dmx: {
birthplace: "Mount Vernon, NY"
}
}
console.log(ruff_ryders.lox.birthplace);
Cannot read property 'birthplace' of undefined
What does the following code print to the console?
var ruff_ryders = {
dmx: {
birthplace: "Mount Vernon, NY"
}
}
console.log(ruff_ryders.lox && ruff_ryders.lox.birthplace);
undefined
What does the following code print to the console?
var a = {
x: "y"
}
console.log("x" in a);
true
What does the following code print to the console?
var abc = {
zz: "ll"
}
console.log(abc.hasOwnProperty("zz"));
true
Add a real_name property to the following dmx object with the value "Earl Simmons".
var dmx = {
occupation: "rapper"
}
dmx.real_name = "Earl Simmons";
Add a circumference method to the following circle object that returns the circumference of the circle (Pi equals Math.PI).
var circle = {
radius: 10
}
circle.circumference = function() {
return this.radius * Math.PI * 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment