JavaScript Course | Practice Quiz-2

  • Last Updated : 10 May, 2019


1
Question 1
Which of the following javascript functions allows you to get user input data?
A
alert
B
prompt
C
confirm
D
None of the above
JavaScript Course Quiz 2    
Discuss it


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?
A
&&(AND)
B
||(OR)
C
!(NOT)
D
None of the above
JavaScript Course Quiz 2    
Discuss it


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>
A
0
B
1
C
true
D
3
JavaScript Course Quiz 2    
Discuss it


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>
A
0
B
false
C
true
D
1
JavaScript Course Quiz 2    
Discuss it


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>
A
0
B
infinity
C
NaN
D
None of the above
JavaScript Course Quiz 2    
Discuss it


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>
A
Hola
B
Breaking up the code
C
Adios
D
None of the above
JavaScript Course Quiz 2    
Discuss it


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>
A
true
B
false
C
0
D
None of the above
JavaScript Course Quiz 2    
Discuss it


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>
A
Great
B
Not so great
C
true
D
None of the above
JavaScript Course Quiz 2    
Discuss it


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>
A
string
B
null
C
number
D
boolean
JavaScript Course Quiz 2    
Discuss it


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>
A
undefined
B
string
C
number
D
boolean
JavaScript Course Quiz 2    
Discuss it


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.
1
My Personal Notes arrow_drop_up