let greeting;
greetign = {};
console.log(greetign);
- A:
{}
- B:
ReferenceError: greetign is not defined
- C:
undefined
Answer
In this code, declare a variable named greetign
, then when you attempt to assign an empty object then you write wrong variable name greetign
. That's why JavaScript give ReferenceError
function sum(a, b) {
return a + b;
}
sum(1, "2");
- A:
NaN
- B:
TypeError
- C:
"12"
- D:
3
Answer
In JavaScript, when you use plus operator +
with a string then it performs concatenation. You Provide 2 as a string, that's why the result is 12
.
const food = ["🍕", "🍫", "🥑", "🍔"];
const info = { favoriteFood: food[0] };
info.favoriteFood = "🍝";
console.log(food);
- A:
['🍕', '🍫', '🥑', '🍔']
- B:
['🍝', '🍫', '🥑', '🍔']
- C:
['🍝', '🍕', '🍫', '🥑', '🍔']
- D:
ReferenceError
Answer
In here, info.favoriteFood
reassigned "🍝", but it's never effect original array. That's why result is the original array
function sayHi(name) {
return `Hi there, ${name}`;
}
console.log(sayHi());
- A:
Hi there,
- B:
Hi there, undefined
- C:
Hi there, null
- D:
ReferenceError
Answer
In this code, the sayHi
function except a parameter name
. but when call the function without parameter and also without default parameter then the function return undefined. then Hi there
and undefined add. So result is Hi there, undefined
let count = 0;
const nums = [0, 1, 2, 3];
nums.forEach((num) => {
if (num) count += 1;
});
console.log(count);
- A: 1
- B: 2
- C: 3
- D: 4