Last active
August 12, 2022 22:22
-
-
Save RavenHursT/e6ccc44723731f9322cd to your computer and use it in GitHub Desktop.
Questions for JavaScript phone screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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