A

Admin • 828.03K Points
Coach

Q. Which of the following is not considered as an error in JavaScript?

  • (A) Missing of Bracket
  • (B) Syntax error
  • (C) Missing of semicolons
  • (D) Division by zero
  • Correct Answer - Option(D)
  • Views: 14
  • Filed under category JavaScript
  • Hashtags:

Explanation by: Admin

In JavaScript, dividing a number by zero does not throw an error. Instead, it returns Infinity (or -Infinity for negative numbers). JavaScript handles division by zero gracefully, unlike some other languages where it may cause an error.

Example:

console.log(10 / 0);  // Output: Infinity
console.log(-10 / 0); // Output: -Infinity

However, if the value is 0/0, it results in NaN (Not-a-Number):

console.log(0 / 0); // Output: NaN

Why Not Other Options?

  • (A) Missing of Bracket → ❌ Error (Missing brackets can cause syntax errors).
  • (B) Syntax error → ❌ Error (Incorrect syntax results in a SyntaxError).
  • (C) Missing of semicolons → ❌ Error (Although JavaScript has automatic semicolon insertion, in some cases, missing semicolons can lead to unexpected behavior or errors).

Final Answer:

(D) Division by zero (It returns Infinity instead of throwing an error).

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.