Simple JS Screening Test
Simple Screening for testing fundamental JS knowledge
by Matthew Marcus
JavaScript
//What does this do? What is it called?
(function(){
// Code
}());
//What does this output?
var obj = {
foo: 'FOO',
func: function() {
var self = this;
console.log(this.foo);
console.log(self.foo);
(function() {
console.log(this.foo);
console.log(self.foo);
}())
}
};
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? 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`)
}
}
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()