JavaScript Course | Practice Quiz-2
Question 1 |
Which of the following javascript functions allows you to get user input data?
alert | |
prompt | |
confirm | |
None of the above |
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?
&&(AND) | |
||(OR) | |
!(NOT) | |
None of the above |
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>
0 | |
1 | |
true | |
3 |
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>
0 | |
false | |
true | |
1 |
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>
0 | |
infinity | |
NaN | |
None of the above |
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>
Hola | |
Breaking up the code | |
Adios | |
None of the above |
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>
true | |
false | |
0 | |
None of the above |
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>
Great | |
Not so great | |
true | |
None of the above |
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>
string | |
null | |
number | |
boolean |
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>
undefined | |
string | |
number | |
boolean |
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.