JSFiddle - React, Tailwind, and code Playground
by upigilam
JavaScript
/* //hello kyle
// intern interview 1st question
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
getArea() {
return this.height * this.width;
}
get area() {
return this.height * this.width;
}
static isRectangle(obj) {
return obj instanceof Rectangle;
}
}
class Square extends Rectangle {
constructor(side) {
super(side, side);
}
}
// Write a class named Rectangle that takes a height and width param
const myRectangle = new Rectangle(10 height, 5 width);
// Write an instance method that calculates the area of the rectangle
console.log(myRectangle.getArea()); // returns 50
// How would we get the area using a getter?
myRectangle.area // returns 50
// How would we write a class method?
console.log(Rectangle.isRectangle(myRectangle)); // true
// How would we write a subclass?
const mySquare = new Square(5 side);
*/
// What happens when the new keyword is used?
// intern interview 2nd question
//Determine the output of the code below
var myObject = {
egg: “plant”,
func: function() {
var self = this;
console.log(“outer func: this.egg = “ + this.egg);
console.log(“outer func: self.egg = “ + self.egg);
(function() {
console.log(“inner func: this.egg = “ + this.egg);
console.log(“inner func: self.egg = “ + self.egg);
}());
}
};
myObject.func();