var greeting = 'Hello';
console.log(greeting); // prints: Hello
if (true) {
var greeting = 'Hi';
console.log(greeting); // prints: Hi
}
console.log(greeting); // prints: Hi
let greeting = 'Hello';
console.log(greeting); // prints: Hello
if (true) {
let greeting = 'Hi';
console.log(greeting); // prints: Hi
}
console.log(greeting); // prints: Hello
const modeObject = {
show: function() {
return this
},
showArrow: () => this
}
modeObject.show(); // prints: { show: ƒ, showArrow: ƒ }
modeObject.showArrow(); // prints: Window
class Shopkeeper {
talk() {
// Return a randon item from the array
const words = this.lines[Math.floor(Math.random() * this.lines.length)];
console.log(words);
}
}
Shopkeeper.prototype.lines = ["Can I interest you in some wares?", "Welcome, weary traveler"];
class Shopkeeper {
talk() {
// Return a randon item from the array
const words = this.lines[Math.floor(Math.random() * this.lines.length)];
console.log(words);
}
}
Shopkeeper.prototype.lines = ["Can I interest you in some wares?", "Welcome, weary traveler"];
var artifactDealer = new Shopkeeper();
var clothingSeller = new Shopkeeper();
artifactDealer.lines = ["Grumble, grumble."];
clothingSeller.talk() // prints: ?
class Shopkeeper {
talk() {
// Return a randon item from the array
const words = this.lines[Math.floor(Math.random() * this.lines.length)];
console.log(words);
}
}
Shopkeeper.prototype.lines = ["Can I interest you in some wares?", "Welcome, weary traveler"];
var artifactDealer = new Shopkeeper();
var clothingSeller = new Shopkeeper();
artifactDealer.lines.push("Grumble, grumble.");
clothingSeller.talk() // prints: ?
class Shopkeeper {
talk() {
// Return a randon item from the array
const words = this.lines[Math.floor(Math.random() * this.lines.length)];
console.log(words);
}
}
Shopkeeper.prototype.lines = ["Can I interest you in some wares?", "Welcome, weary traveler"];
var artifactDealer = new Shopkeeper();
var clothingSeller = new Shopkeeper();
artifactDealer.lines = ["Grumble, grumble."];
artifactDealer.talk() // prints: ?
delete artifactDealer.lines;
artifactDealer.lines // prints: ?