Q. What does the Javascript “debugger” statement do?

  • (A) It will debug all the errors in the program at runtime.
  • (B) It acts as a breakpoint in a program.
  • (C) It will debug error in the current statement if any.
  • (D) All of the above.
πŸ’¬ Discuss
βœ… Correct Answer: (B) It acts as a breakpoint in a program.

Q. What will be the output of the following code snippet?

Code:
var a = Math.max();
var b = Math.min();
print(a);
print(b);
  • (A) -Infinity Infinity
  • (B) Infinity -Infinity
  • (C) Infinity Infinity
  • (D) -Infinity -Infinity
πŸ’¬ Discuss
βœ… Correct Answer: (A) -Infinity Infinity
Explanation:

Let's go through this carefully.

You have this JavaScript code:

var a = Math.max();
var b = Math.min();
print(a);
print(b);

Now:

  • Math.max() with no arguments returns -Infinity.
  • Math.min() with no arguments returns Infinity.

Why?
Because:

  • Math.max() needs numbers to find the maximum. With no numbers, it returns the lowest possible value (-Infinity).
  • Math.min() needs numbers to find the minimum. With no numbers, it returns the highest possible value (Infinity).

Thus:

  • a = -Infinity
  • b = Infinity

So, the output will be:

-Infinity
Infinity

Therefore, the correct answer is:

(A) -Infinity Infinity

Q. What will be the output of the following code snippet?

Code:
var a = Math.max() < Math.min();
var b = Math.max() > Math.min();
print(a);
print(b);
  • (A) true false
  • (B) false true
  • (C) true true
  • (D) false false
πŸ’¬ Discuss
βœ… Correct Answer: (A) true false

Q. Which of the following are not server-side Javascript objects?

  • (A) Date
  • (B) FileUpload
  • (C) Function
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of the above

Q. What will be the output of the following code snippet?

Code:
const obj1 = {first: 20, second: 30, first: 50};
console.log(obj1);
  • (A) {first: 20, second: 30}
  • (B) {first: 50, second: 30}
  • (C) {first: 20, second: 30, first: 50}
  • (D) Syntax Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) {first: 50, second: 30}

Q. Which object in Javascript doesn’t have a prototype?

  • (A) Base Object
  • (B) All objects have a prototype
  • (C) None of the objects have a prototype
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) Base Object

Q. How do we write a comment in javascript?

  • (A) /* */
  • (B) //
  • (C) #
  • (D) $ $
πŸ’¬ Discuss
βœ… Correct Answer: (B) //

Q. What happens when we run this code?

Code:
function dog() {
   print("I am a dog.");
}
dog.sound = "Bark";
  • (A) Syntax Error
  • (B) “I am a dog” gets printed
  • (C) ReferenceError
  • (D) Nothing happens
πŸ’¬ Discuss
βœ… Correct Answer: (D) Nothing happens

Q. What will be the output of the following code snippet?

Code:
const obj1 = {Name: "Hello", Age: 16};
const obj2 = {Name: "Hello", Age: 16};
print(obj1 === obj2);
  • (A) true
  • (B) false
  • (C) Undefined
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) false

Q. What will be the output of the following code snippet?

Code:
let n = 24;
let l = 0, r = 100, ans = n;
while(l <= r) {
   let mid = Math.floor((l + r) / 2);
   if(mid * mid <= n) {
       ans = mid;
       l = mid + 1;
   }
   else {
       r = mid - 1;
   }
}
print(ans);
  • (A) 3
  • (B) 4
  • (C) 5
  • (D) 6
πŸ’¬ Discuss
βœ… Correct Answer: (B) 4