JavaScript Output-Based Questions
1.
let a = 10;
(function () {
[Link](a);
let a = 20;
})();
2.
const obj = {
a: 1,
b: function () {
[Link](this.a);
}
};
const a = 100;
[Link](null);
3.
function foo() {
return
{
bar: "baz"
};
}
[Link](typeof foo());
4.
[Link]([] + []);
[Link]([] + {});
[Link]({} + []);
5.
function makeCounter() {
let count = 0;
return function () {
return count++;
};
}
const counter1 = makeCounter();
const counter2 = makeCounter();
[Link](counter1());
[Link](counter1());
[Link](counter2());
6.
let x = 5;
const y = x++;
[Link](x);
[Link](y);
7.
const obj = {
message: 'Hello',
greet: () => {
[Link]([Link]);
}
};
[Link]();
8.
(async function() {
await [Link]();
[Link](1);
})();
[Link](2);
9.
let arr = [10, 20, 30];
arr[100] = 1000;
[Link]([Link]);
10.
var x = 21;
var fun = function () {
[Link](x);
var x = 20;
};
fun();
11.
let a = { x: 1 };
let b = a;
a.x = 2;
a = { x: 3 };
[Link](b.x);
12.
let a = 1;
{
let a = 2;
{
let a = 3;
[Link](a);
}
[Link](a);
}
[Link](a);
13.
for (var i = 0; i < 3; i++) {
setTimeout(() => [Link](i), 100);
}
14.
[Link](typeof null);
[Link](null instanceof Object);
15.
const func = (function() {
let counter = 0;
return function() {
return ++counter;
}
})();
[Link](func());
[Link](func());
16.
let obj = { name: "JS" };
[Link](obj);
[Link] = "JavaScript";
[Link]([Link]);
17.
let x = NaN;
[Link](x === x);
18.
function A() {
[Link] = "A";
return { name: "B" };
}
const obj = new A();
[Link]([Link]);
19.
function* gen() {
yield 1;
yield 2;
yield 3;
}
const g = gen();
[Link]([Link]().value);
[Link]([Link]().value);
[Link]([Link]().value);
20.
let num = 0;
[Link](num++);
[Link](++num);
21.
[Link](1 < 2 < 3);
[Link](3 > 2 > 1);
22.
(function() {
var a = b = 5;
})();
[Link](typeof b);
[Link](typeof a);
23.
const a = [1, 2, 3];
[Link] = 0;
[Link](a[0]);
24.
function Person() {}
[Link] = () => {
[Link]("Hi");
};
const p = new Person();
[Link]();
25.
let obj = {
get value() {
return 42;
}
};
[Link]([Link]);
26.
let count = 0;
const intervalId = setInterval(() => {
[Link](count++);
if (count > 2) clearInterval(intervalId);
}, 10);
27.
let a = [1, 2];
let b = [1, 2];
[Link](a == b);
[Link](a === b);
28.
let x = 0;
if (true) {
let x = 1;
if (true) {
let x = 2;
[Link](x);
}
[Link](x);
}
[Link](x);
29.
const x = "5";
const y = 5;
[Link](x == y);
[Link](x === y);
30.
let obj = {
name: "John",
getName: function () {
return [Link];
}
};
let getName = [Link];
[Link](getName());