Skip to content

Instantly share code, notes, and snippets.

@RavenHursT
Last active August 12, 2022 22:22
Show Gist options
  • Save RavenHursT/e6ccc44723731f9322cd to your computer and use it in GitHub Desktop.
Save RavenHursT/e6ccc44723731f9322cd to your computer and use it in GitHub Desktop.
Questions for JavaScript phone screen
//What does this do? What is it called? What is it typically used for?
(function () {
// Code
})();
//What does this do and what does it output?
function Obj() {
this.foo = "FOO"
this.func = function () {
var self = this
console.log(this.foo)
console.log(self.foo)
(function () {
console.log(self.foo)
console.log(this.foo)
})()
}
}
var obj = new Obj()
obj.func()
//What does this output?
;(function () {
console.log(1)
setTimeout(() => {
console.log(2)
}, 1000)
setTimeout(() => {
console.log(3)
}, 0)
console.log(4)
})()
// Do you see anything wrong w/ how this class is implemented, regarding runtime *performance*?
// How can it be optimized?
var Car = function () {
this.revs = 0
this.start = () => {
this.revs = 1000
this.status()
};
this.accelerate = () => {
this.revs += 1000
this.status()
};
this.decelerate = () => {
this.revs -= 1000
this.status()
};
this.status = () => {
console.log(`revs => `, `${this.revs}RPM`)
}
}
// This is just a simple example of how the above class may be used
var cars = []
for (var i = 0; i < 1001; i++) {
cars.push(new Car())
}
cars[100].start()
cars[100].accelerate()
cars[100].accelerate()
cars[100].accelerate()
cars[100].decelerate()
cars[100].decelerate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment