JavaScript Multiple Choice Questions
31.Which of the following function of Array object applies a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value?
A - pop()
B - reduce()
C - push()
D - reduceRight()
View Answer
Ans : D
Explanation:reduceRight() − Applies a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
32. What is the output of following Javascript?
var a = 'letsfind';
var b = 'course';
var c = a/b;
document.write(c);
A. letsfindcourse
B. letsfind/course
C. NaN
D. None of the above
View Answer
Ans : C
Explanation: he output of following Javascript is NaN.
33. How ++ works in Javascript? Find output of below Javascript code.
var a = 1;
document.write(a--);
document.write(a);
A. 00
B. 01
C. 11
D. 10
View Answer
Ans : D
Explanation: document.write(a--); will print 1 and after than it will decrement the variable a value to 0 , next line document.write(a); will print 0.
34. Find output of below Javascript addition code
document.write("1 plus 1 is " + 1 + 1);
A. 2
B. 1 plus 1 is 2
C. 1 plus 1 is 11
D. 1 plus 1 is 1 + 1
View Answer
Ans : C
Explanation:output of below Javascript addition code is 1 plus 1 is 11.
35.In JavaScript, Arrays are data type. State True or False
A. True
B. False
View Answer
Ans : B
Explanation:In JavaScript, Arrays is not data type.
JavaScript - The Arrays Object. The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type.
36. Does JavaScript allow exception handling?
A. Yes, it provides try, catch as well as throw key word for exception handling
B. Yes, but it provides only try block
C. Yes, but it provides only Try catch block, but does not allow throw exception
D. No
View Answer
Ans : A
Explanation:JavaScript implements the try...catch...finally construct as well as the throw operator to handle exceptions. You can catch programmer-generated and runtime exceptions, but you cannot catch JavaScript syntax errors.
37. Which of the following method checks if its argument is not a number?
A. isNaN()
B. nonNaN()
C. NaN()
D. None of the above
View Answer
Ans : A
Explanation:The Number.isNaN() method determines whether a value is NaN (Not-A-Number). This method returns true if the value is of the type Number, and equates to NaN. Otherwise it returns false.
38. What if you use parseInt() to convert a string containing decimal value?
A. Throws Error
B. It returns the decimal values in string form
C. If returns only the integer portion of the number
D. None of the listed option
View Answer
Ans : C
Explanation: JavaScript's parseInt function is all about converting a string to an integer. The function takes a string value as an argument and converts it to a numerical value with no decimal places, or alternatively the value NaN.
39. What is the output of below Javascript code?
alert (typeof new Date() );
A. Throws Error
B. object
C. Displays Nothing
D. Current Date
View Answer
Ans : B
Explanation: The typeof is an operator keyword which is used to get a type at the compile-time. Or in other words, this operator is used to get the System.Type object for a type.
40. What if we put ++ operator inside if condition? find the output of below code
< script>
var a = 10;
if(a == a++)
document.write(a);
script>
A. Error
B. Nothing is printed
C. 10
D. 11
View Answer
Ans : D
Explanation:During initialization the value of variable a is 10.But after if condition it becomes 11 due to "a++" in if condition.
Also check :
Discussion