πŸ“Š JavaScript
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
πŸ’¬ Discuss
βœ… Correct Answer: (D) Division by zero

Explanation:

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).

Explanation by: Mr. Dubey

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).

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
337
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Kirti
Publisher
πŸ“ˆ
98%
Success Rate