Skip to content

Instantly share code, notes, and snippets.

View jasminegmp's full-sized avatar

Jasmine jasminegmp

  • Orange County, California
View GitHub Profile
//For the following:
var a = `foo ${b}`, b = `bar ${a}`;
console.log(a);
//Why would console.log output 'foo' and then 'undefined'?
//Is it because b is defined after a?
//If that's true, then why does the following code output 'foo bar undefined'?:
var b = `bar ${a}`, a = `foo ${b}`;
console.log(a);
let myObject = function(obj){
obj.sayName = function(){
console.log(this.name);
}
}
let me = {
name: 'Jasmine'
}
let createUser = function(name){
return{
name,
sayNames: function() {console.log(this.name)},
dog: {
name: 'Jello',
sayNames: function() {console.log(name + "'s dog's name is " + this.name)}
}
}
}
//call
let john = {
name: 'John'
}
let hobbies = ['painting', 'cooking', 'biking'];
let setName = function(hobby0, hobby1){
console.log(this.name + "'s hobbies are " + hobby0 + " and " + hobby1);
}
let john = {
name: 'John'
}
let hobbies = ['painting', 'cooking', 'biking'];
let setName = function(hobby0, hobby1){
console.log(this.name + "'s hobbies are " + hobby0 + " and " + hobby1);
}
let john = {
name: 'John'
}
let hobbies = ['painting', 'cooking', 'biking'];
let setName = function(hobby0, hobby1){
console.log(this.name + "'s hobbies are " + hobby0 + " and " + hobby1);
}
let Dog = function(breed){
this.breed = breed;
}
let chihuahua = new Dog('Chihuahua');
console.log(chihuahua); // will output Dog { breed: 'Chihuahua' }
let global = 'I see global.'
function scopeFunction(){
console.log(global);
}
scopeFunction(); // outputs 'I see global.'
function myFunction(){
var localFunction = 'I see local';
console.log(localFunction);
}
myFunction(); // outputs 'I see functional scope'
console.log(localFunction); // Outputs an error 'localFunction is not defined'
var a = 'hi';
function myFunction(){
console.log(a);
var a = 'hello';
console.log(a);
}
myFunction();