let greeting;
greetign = {};
console.log(greetign);
- A:
{}
- B:
ReferenceError: greetign is not defined
- C:
undefined
Answer
Here a variable is declared with Let, the name of the variable is greeting. And later an empty object has been reassigned inside it. So after running the code we got empty object object as output.
function sum(a, b) {
return a + b;
}
sum(1, "2");
- A:
NaN
- B:
TypeError
- C:
"12"
- D:
3
Answer
Here A and B are passed as parameters inside a function called sum. And inside the function the sum of the two parameters is returned. And when calling from function 1 is sent as integer and 2 is sent as string. So we got 12 as output.
const food = ["🍕", "🍫", "🥑", "🍔"];
const info = { favoriteFood: food[0] };
info.favoriteFood = "🍝";
console.log(food);
- A:
['🍕', '🍫', '🥑', '🍔']
- B:
['🍝', '🍫', '🥑', '🍔']
- C:
['🍝', '🍕', '🍫', '🥑', '🍔']
- D:
ReferenceError
Answer
Here an array is kept inside a variable called food, and many foods are kept inside the array. And an object is placed inside the variable named info. Here food is console.log so we get an array as output.
function sayHi(name) {
return `Hi there, ${name}`;
}
console.log(sayHi());
- A:
Hi there,
- B:
Hi there, undefined
- C:
Hi there, null
- D:
ReferenceError
Answer
Here is a function called sayHi. The function takes a parameter named name. And the parameter is returned dynamically inside the function. And while console.log , the function is called without parameter value. So Hi there, undefined is obtained as output.
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
Answer
The code provided will output 3 to the console. In this code, have an array nums containing four elements: [0, 1, 2, 3]. then use the forEach method to iterate over each element in the array. Inside the callback function, you check if the current num is truthy (i.e., not equal to 0), and if it is, you increment the count variable by 1. After iterating through all the elements, the count variable contains the count of truthy values in the nums array, which is 3. Hence, when console.log(count), it will output 3.