Skip to content

Instantly share code, notes, and snippets.

@egrueter-dev
egrueter-dev / function-constructors-2.js
Created June 27, 2016 00:07
Function Constructors
console.log(john);
// => Person {Firstname: “John”, Lastname: “Doe” }
function Person() {
this.firstname = ‘John’
this.lastname = ‘Doe’
console.log(`This function is invoked!`)
}
var john = new Person();
//=> "This function is invoked!"
function Person() {
console.log(this);
}
var john = new Person();
//=> Person {}
function Person() {
this.firstname = 'John'
this.lastname = 'Doe'
}
var john = new Person();
var Sally = new Person();
console.log(john);
console.log(sally);
function Person(firstname, lastname) {
this.firstname = firstname
this.lastname = lastname
}
var john = new Person(‘john’, ‘doe’);
var sally = new Person(‘sally’, ‘white’);
//=> Person { Firstname: “John”, Lastname: “Doe” }
//=> Person { Firstname: “Sally”, Lastname: “White” }
var width = 100;
console.log (width); //=> 100
var width = 100;
console.log (width); //=> 100
var width = 200
console.log (width); //=> 200
function setWidth() {
var width = 100;
console.log(width);
}
/// width not available here
if(age > 12) {
const dogYears = age * 7
console.log(‘You are ${dogYears} dog years old!’)
}
//=> dogYears not available here
if(age > 12) {
let dogYears = age * 7
console.log(‘You are ${dogYears} dog years old!’)
}
//=> dogYears not available here