JavaScript Course | Practice Quiz-2

Question 1
Which of the following javascript functions allows you to get user input data?
Cross
alert
Tick
prompt
Cross
confirm
Cross
None of the above


Question 1-Explanation: 
Only prompt creates an input field where the user can enter the data.
Question 2
Which logical operator only accepts a single operand?
Cross
&&(AND)
Cross
||(OR)
Tick
!(NOT)
Cross
None of the above


Question 2-Explanation: 
Only the !(NOT) operator takes a single operand. It flips the value.
Question 3
What will be the result of the following code?
<script>
  document.write( true && 1 && 3);
</script>
Cross
0
Cross
1
Cross
true
Tick
3


Question 3-Explanation: 
The && (and operator) returns the last (right-side) value as long as the chain is \"truthy\" or True.
Question 4
What will be the output of the following code?
 <script>
   document.write((0 && 1) || (1 || 0));
 </script>
Cross
0
Cross
false
Cross
true
Tick
1


Question 4-Explanation: 
The && (and operator) returns the last (right-side) value as long as the chain is \"truthy\". The || (or operator) returns true if either of the value is true.
Question 5
What will be the output of the following code?
<script>
 let ans = 0 / 0;
 document.write(ans);
</script>
Cross
0
Cross
infinity
Tick
NaN
Cross
None of the above


Question 5-Explanation: 
0/0 is undefined for the real number and is therefore represented by NaN (Not a Number) in Javascript.
Question 6
What will be the output of the following code?
<script>
 let i = 30;
  if( i == 10 || i > 20){
    console.log('Hola');
  }else if( i == 5){
    console.log('Breaking up the code');
  }else{
    console.log('Adios');
 }
</script>
Tick
Hola
Cross
Breaking up the code
Cross
Adios
Cross
None of the above


Question 6-Explanation: 
The if() statement will be executed if the condition in the bracket returns true otherwise the else statement is executed.
Question 7
What will be the output of the following code?
 <script>
   let ans = 1;
   document.write( ans === '1');
 </script>
Cross
true
Tick
false
Cross
0
Cross
None of the above


Question 7-Explanation: 
The strict equality operator compares both the value and the type of the operands.
Question 8
What will be the output of the following code?
 <script>
  let age = 20;
  let result = age>18 ? 'Great' : 'Not so great';
  document.write(result);
 </script>
Tick
Great
Cross
Not so great
Cross
true
Cross
None of the above


Question 8-Explanation: 
?: is a ternary operator which will return the value after \'?\' if true else it will return the value after \':\'.
Question 9
What will be the output of the following code?
<script>
  let y = 1;
  y = typeof x; 
  document.write(typeof y);
</script>
Tick
string
Cross
null
Cross
number
Cross
boolean


Question 9-Explanation: 
typeof \'undefined\' is a string and if we do typeof \'string\' again it will be the same.
Question 10
What will be the output of the following code?
 <script>
    var x = [typeof x, typeof y][1];
    document.write(typeof typeof x);
 </script>
Cross
undefined
Tick
string
Cross
number
Cross
boolean


Question 10-Explanation: 
typeof \'y\' which is undefined returns \'undefined\', typeof \'undefined\' is \'string\', and another typeof on it still returns \'string\'.
There are 10 questions to complete.


  • Last Updated : 27 Sep, 2023

Share your thoughts in the comments
Similar Reads