Q. Which of the following is the correct output for the following JavaScript code

Code:
var grade='Z';  
var result;  
switch(grade)  
{  
case'A':  
        result+="10";  
case'B':  
        result+=" 9";  
case'C':  
        result+=" 8";  
default:  
        result+=" 0";  
}  
document.write(result);  
  • (A) 10
  • (B) 17
  • (C) 18
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (D) 0

Q. Which of the following variables takes precedence over the others if the names are the same?

  • (A) Global variable
  • (B) The local element
  • (C) The two of the above
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) The local element

Q. Which one of the following is the correct way for calling the JavaScript code?

  • (A) Preprocessor
  • (B) Triggering Event
  • (C) RMI
  • (D) Function/Method
πŸ’¬ Discuss
βœ… Correct Answer: (D) Function/Method

Q. Which of the following type of a variable is volatile?

  • (A) Mutable variable
  • (B) Dynamic variable
  • (C) Volatile variable
  • (D) Immutable variable
πŸ’¬ Discuss
βœ… Correct Answer: (A) Mutable variable

Q. Which of the following option is used as hexadecimal literal beginning?

  • (A) 00
  • (B) 0x
  • (C) 0X
  • (D) Both 0x and 0X
πŸ’¬ Discuss
βœ… Correct Answer: (D) Both 0x and 0X

Q. When there is an indefinite or an infinite value during an arithmetic computation in a program, then JavaScript prints______.

  • (A) Prints an exception error
  • (B) Prints an overflow error
  • (C) Displays "Infinity"
  • (D) Prints the value as such
πŸ’¬ Discuss
βœ… Correct Answer: (C) Displays "Infinity"

Q. In the JavaScript, which one of the following is not considered as an error:

  • (A) Syntax error
  • (B) Missing of semicolons
  • (C) Division by zero
  • (D) Missing of Bracket
πŸ’¬ Discuss
βœ… Correct Answer: (C) Division by zero

Q. Which of the following givenfunctions of the Number Object formats a number with a different number of digits to the right of the decimal?

  • (A) toExponential()
  • (B) toFixed()
  • (C) toPrecision()
  • (D) toLocaleString()
πŸ’¬ Discuss
βœ… Correct Answer: (B) toFixed()

Q. Which of the following number object function returns the value of the number?

  • (A) toString()
  • (B) valueOf()
  • (C) toLocaleString()
  • (D) toPrecision()
πŸ’¬ Discuss
βœ… Correct Answer: (B) valueOf()
Explanation:

valueOf():
Returns the primitive value of a Number object.
βœ… Correct answer

toString():
Converts the number to a string.

toLocaleString():
Returns a string with a language-sensitive representation of the number.

toPrecision():
Formats the number to a specified precision and returns it as a string.

Example:

let num = new Number(42);

console.log(num.valueOf()); // 42
console.log(num.toString()); // "42"
console.log(num.toLocaleString()); // e.g., "42" (depends on locale)
console.log(num.toPrecision(2)); // "42"

? Only valueOf() returns the raw numeric value.

βœ… Answer: (B) valueOf()

Q. Which of the following function of the String object returns the character in the string starting at the specified position via the specified number of characters?

  • (A) slice()
  • (B) split()
  • (C) substr()
  • (D) search()
πŸ’¬ Discuss
βœ… Correct Answer: (C) substr()