- What is the output of the following code?
console.log(typeof NaN);
a) "undefined" b) "number" c) "NaN" d) "object"
-
Which of the following is NOT a valid way to declare a variable in JavaScript? a)
var x = 5;
b)let y = 10;
c)const z = 15;
d)int w = 20;
-
What will be the value of
x
after this code executes?
let x = 5;
x += "2";
a) 7 b) "52" c) 52 d) "7"
-
Which of these Array methods does NOT modify the original array? a) push() b) pop() c) splice() d) slice()
-
What is the output of this code?
const obj = {a: 1, b: 2};
const {a, c = 3} = obj;
console.log(c);
a) undefined b) 2 c) 3 d) ReferenceError
- What is the output of the following code?
console.log(typeof typeof 1);
- Will the following code produce an error? If not, what will it output?
let a = 1;
let b = 2;
[a, b] = [b, a];
console.log(a, b);
- Compare the following two code blocks. What will be the difference in their outputs?
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
- What is the value of
x
after the following code executes?
let x = 10;
(function() {
x = 20;
})();
- What is the output of the following code?
const arr = [1, 2, 3];
arr[10] = 10;
console.log(arr.length);
- What is the output of the following code?
function foo() {
return {
bar: "hello"
};
}
function baz() {
return
{
bar: "hello"
};
}
console.log(foo());
console.log(baz());
- Explain the difference between the 2 code blocks
const ids = [1, 2, 3, 4, 5];
const endpoint = 'https://jsonplaceholder.typicode.com/posts';
for (const id of ids) {
try {
const response = await fetch(`${endpoint}/${id}`);
await response.json();
} catch (error) {
console.error(error);
}
}
const ids = [1, 2, 3, 4, 5];
const endpoint = 'https://jsonplaceholder.typicode.com/posts';
try {
for (const id of ids) {
const response = await fetch(`${endpoint}/${id}`);
await response.json();
}
} catch (error) {
console.error(error);
}