JS Implementation Question Resources
JS Implementation Question Resources
Question Resources
● 1: Undefined
● 2: ReferenceError
● 3: null
● 4: {model: "Honda", color: "white", year: "2010", country: "UK"}
4. What’s the output of this code?
function foo() {
let x = y = 0;
x++;
y++;
return x;
}
● 1: A, B and C
● 2: B, A and C
● 3: A and C
● 4: A, C and B
6. What’s the output of this code?
var y = 1;
if (function f(){}) {
y += typeof f;
}
console.log(y);
● 1: 1function
● 2: 1object
● 3: ReferenceError
● 4: 1undefined
● 1: true, true
● 2: true, false
● 3: SyntaxError, SyntaxError,
● 4: false, false
9. What’s the output of this code in non-strict mode?
function printNumbers(first, second, first) {
printNumbers(1, 2, 3);
● 1: 1, 2, 3
● 2: 3, 2, 3
● 3: SyntaxError: Duplicate parameter name not allowed in this context
● 4: 1, 2, 1
● 1: SyntaxError
● 2: It is not a string!, It is not a number!
● 3: It is not a string!, It is a number!
● 4: It is a string!, It is a number!
new A();
new B();
1: A, A
2: A, B
17. What’s the output of the following code?
const [x, ...y,] = [1, 2, 3, 4];
console.log(x, y);
1: 1, [2, 3, 4]
2: 1, [2, 3]
3: 1, [2]
4: SyntaxError
18. What’s the output of the following code?
const {a: x = 10, b: y = 20} = {a: 30};
console.log(x);
console.log(y);
1: 30, 20
2: 10, 20
3: 10, undefined
4: 30, undefined
19. What’s the output of the following code?
function area({length = 10, width = 20}) {
console.log(length*width);
}
area();
1: 200
2: Error
3: undefined
4: 0
1: Tom
2: Error
3: undefined
4: John
21. What’s the output of the following code?
function add(item, items = []) {
items.push(item);
return items;
}
console.log(add('Orange'));
console.log(add('Apple'));
1: ['Orange'], ['Orange', 'Apple']
2: ['Orange'], ['Apple']
myFun(1, 2, 3, 4, 5);
myFun(1, 2);
1: [3, 4, 5], undefined
2: SyntaxError
3: [3, 4, 5], []
2: undefined
3: SyntaxError
4: TypeError
(function innerFunc() {
if (count === 10) {
let count = 11;
console.log(count);
}
console.log(count);
})();
1: 11, 10
2: 11, 11
3: 10, 11
4: 10, 10
25. What’s the output of the following code?
let zero = new Number(0);
if (zero) {
console.log("If");
} else {
console.log("Else");
}
start() {
console.log(`${this.name} vehicle started`);
}
}
Person.prototype.walk = function() {
return this;
}
Person.run = function() {
return this;
}
● 1: undefined, undefined
● 2: Person, Person
● 3: SyntaxError
● 4: Window, Window
28. What’s the output of the following code?
const squareObj = new Square(10);
console.log(squareObj.area);
class Square {
constructor(length) {
this.length = length;
}
get area() {
return this.length * this.length;
}
set area(value) {
this.area = value;
}
}
● 1: 100
● 2: ReferenceError
var num = 0;
function run(){
console.log(num);
var num = 1;
}
run();
35. What will the code below output to the console and
why?
var myObject = {
foo: "bar",
func: function() {
var self = this;
console.log("outer func: this.foo = " + this.foo);
console.log("outer func: self.foo = " + self.foo);
(function() {
console.log("inner func: this.foo = " + this.foo);
console.log("inner func: self.foo = " + self.foo);
}());
}
};
myObject.func();
36. In what order will the numbers 1-4 be logged to the console
when the code below is executed? Why?
(function() {
console.log(1);
setTimeout(function(){console.log(2)}, 1000);
setTimeout(function(){console.log(3)}, 0);
console.log(4);
})();
37. Consider the code snippet below. What will the console
output be and why?
(function(x) {
return (function(y) {
console.log(x);
})(2)
})(1);
38. Testing your this knowledge in JavaScript: What is the
output of the following code?
var length = 10;
function fn() {
console.log(this.length);
}
var obj = {
length: 5,
method: function(fn) {
fn();
arguments[0]();
}
};
obj.method(fn, 1);