JavaScript Questions and Answers
41.Which of the following is true?
A. If onKeyDown returns false, the key-press event is cancelled.
B. If onKeyPress returns false, the key-down event is cancelled.
C. If onKeyDown returns false, the key-up event is cancelled.
D. If onKeyPress returns false, the key-up event is canceled.
View Answer
Ans : A
Explanation:No explanation.
42. Syntax for creating a RegExp object:
1. var txt=new RegExp(pattern,attributes);
2. var txt=/pattern/attributes;
Which of the above mentioned syntax will correct?
A. 1 only
B. 2 only
C. Both 1 and 2
D. None of the above
View Answer
Ans : C
Explanation: Both the statement are correct.
Both the syntax can be used for creating a RegExp object.
43. If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the paragraph?
A. para1="New Text"
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
View Answer
Ans : B
Explanation: the correct syntax to change the text within the paragraph is "para1.value="New Text";"
44. The syntax of Eval is ________________
A. [objectName.]eval(numeric)
B. [objectName.]eval(string)
C. [EvalName.]eval(string)
D. [EvalName.]eval(numeric)
View Answer
Ans : B
Explanation:The eval() function evaluates or executes an argument. If the argument is an expression, eval() evaluates the expression. If the argument is one or more JavaScript statements, eval() executes the statements.
45. The _______ method of an Array object adds and/or removes elements from an array.
A. Reverse
B. Shift
C. Slice
D. Splice
View Answer
Ans : D
Explanation:The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object
46. Which tag(s) can handle mouse events in Netscape?
A. <IMG>
B. <A>
C. <BR>
D. <span>
View Answer
Ans : A
Explanation:The img element can handle mouse events in Netscape.
47. Consider the following code snippet
const pi=3.14;
var pi=4;
console.log(pi);
What will be the output for the above code snippet?
A. This will flash an error
B. Prints 4
C. Prints 3.14
D. Ambiguity
View Answer
Ans : A
Explanation: Const keyword fixes the value of the variable. Const keyword can not be redefined. Therefore attempts to alter the value or re-declaration causes errors.
48. What is the default value of the asyc attribute?
A. 0
B. 1
C. False
D. True
View Answer
Ans : D
Explanation: The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available. The async attribute optionally accepts a boolean value and by default holds the value true.
49. What is the purpose of the Attr object in the HTML DOM?
A. Used to focus on a particular part of the HTML page
B. HTML Attribute
C. Used to arrange elements
D. None of the mentioned
View Answer
Ans : B
Explanation: In the HTML DOM, the Attr object represents an HTML attribute.
50. Which among the following POSIX signals generate events?
A. SIGDOWN
B. SIGFLOAT
C. SIGINT
D. SIGSHORT
View Answer
Ans : C
Explanation:The SIGINT is a POSIX signal that generates event. A simple code like below can do a proper clean up and exit on CTRL-C or SIGINT passed from command line / other application to the nodejs app’s ProcessID.
Also check :
Discussion