MCQ Single Best Answer Easy

QWhat would the following JavaScript code produce?

<p id="demo"></p>
 <script>
function myFunction() 
{
   var res = "";
   res = res + Number.isFinite(5-2) ;
   document.getElementById("demo").innerHTML = res;
}
</script>


ID: #5024 Javascript Modules MCQ 166 views
Question Info
#5024Q ID
EasyDifficulty
Javascript Modules MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 3True
  • B True
  • C False
  • D Error
Correct Answer: Option B

Explanation

This script defines a function called myFunction() that does the following:
Declares a variable res and initializes it to an empty string.
Concatenates the result of the Number.isFinite() function applied to the expression 5-2 to res.
The Number.isFinite() function returns a boolean value indicating whether the value passed to it is a finite number.
In this case, it would return true. Selects the element with the ID "demo" and changes its inner HTML to the value of res.
When the function is called, the element with the ID "demo" would display the text "true".

Share This Question

Challenge a friend or share with your study group.