Java Script Multiple Choice Questions and Answers-
Sheet 1
1. Why so JavaScript and Java have similar name?
A. JavaScript is a stripped-down version of Java
B. JavaScript's syntax is loosely based on Java's
C. They both originated on the island of Java
D. None of the above
Ans: B
2. When a user views a page containing a JavaScript program, which machine
actually executes the script?
A. The User's machine running a Web browser
B. The Web server
C. A central machine deep within Netscape's corporate offices
D. None of the above
Ans: A
3. ______ JavaScript is also called client-side JavaScript.
A. Microsoft
B. Navigator
C. LiveWire
D. Native
Ans: B
4. __________ JavaScript is also called server-side JavaScript.
A. Microsoft
B. Navigator
C. LiveWire
D. Native
Ans: C
5. What are variables used for in JavaScript Programs?
A. Storing numbers, dates, or other values
B. Varying randomly
C. Causing high-school algebra flashbacks
D. None of the above
Ans: A
6. _____ JavaScript statements embedded in an HTML page can respond to
user events such as mouse-clicks, form input, and page navigation.
A. Client-side
B. Server-side
C. Local
D. Native
Ans: A
7. What should appear at the very end of your JavaScript?
The <script LANGUAGE="JavaScript">tag
A. The </script>
B. The <script>
C. The END statement
D. None of the above
Ans: A
8. Which of the following can't be done with client-side JavaScript?
A. Validating a form
B. Sending a form's contents by email
C. Storing the form's contents to a database file on the server
D. None of the above
Ans: C
9. Which of the following are capabilities of functions in JavaScript?
A. Return a value
B. Accept parameters and Return a value
C. Accept parameters
D. None of the above
Ans: C
10.Which of the following is not a valid JavaScript variable name?
A. 2names
B. _first_and_last_names
C. FirstAndLast
D. None of the above
Ans: A
11. ______ tag is an extension to HTML that can enclose any number of
JavaScript statements.
A. <SCRIPT>
B. <BODY>
C. <HEAD>
D. <TITLE>
Ans: A
12. How does JavaScript store dates in a date object?
A. The number of milliseconds since January 1st, 1970
B. The number of days since January 1st, 1900
C. The number of seconds since Netscape's public stock offering.
D. None of the above
Ans: A
13. Which of the following attribute can hold the JavaScript version?
A. LANGUAGE
B. SCRIPT
C. VERSION
D. None of the above
Ans: A
14. What is the correct JavaScript syntax to write "Hello World"?
A. System.out.println("Hello World")
B. println ("Hello World")
C. document.write("Hello World")
D. response.write("Hello World")
Ans: C
15. Which of the following way can be used to indicate the LANGUAGE
attribute?
A. <LANGUAGE="JavaScriptVersion">
B. <SCRIPT LANGUAGE="JavaScriptVersion">
C. <SCRIPT LANGUAGE="JavaScriptVersion"> JavaScript
statements…</SCRIPT>
D. <SCRIPT LANGUAGE="JavaScriptVersion"!> JavaScript
statements…</SCRIPT>
Ans: C
16. Inside which HTML element do we put the JavaScript?
A. <js>
B. <scripting>
C. <script>
D. <javascript>
Ans: C
17. What is the correct syntax for referring to an external script called " abc.js"?
A. <script href=" abc.js">
B. <script name=" abc.js">
C. <script src=" abc.js">
D. None of the above
Ans: C
18. Which types of image maps can be used with JavaScript?
A. Server-side image maps
B. Client-side image maps
C. Server-side image maps and Client-side image maps
D. None of the above
Ans: B
19. Which of the following navigator object properties is the same in both
Netscape and IE?
A. navigator.appCodeName
B. navigator.appName
C. navigator.appVersion
D. None of the above
Ans: A
20. Which is the correct way to write a JavaScript array?
A. var txt = new Array(1:"tim",2:"kim",3:"jim")
B. var txt = new Array:1=("tim")2=("kim")3=("jim")
C. var txt = new Array("tim","kim","jim")
D. var txt = new Array="tim","kim","jim"
Ans: C
21. What does the <noscript> tag do?
A. Enclose text to be displayed by non-JavaScript browsers.
B. Prevents scripts on the page from executing.
C. Describes certain low-budget movies.
D. None of the above
Ans: A
22. If para1 is the DOM object for a paragraph, what is the correct syntax to
change the text within the paragraph?
A. "New Text"?
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
Ans: B
23. JavaScript entities start with _______ and end with _________.
A. Semicolon, colon
B. Semicolon, Ampersand
C. Ampersand, colon
D. Ampersand, semicolon
Ans: D
24. Which of the following best describes JavaScript?
A. a low-level programming language.
B. a scripting language precompiled in the browser.
C. a compiled scripting language.
D. an object-oriented scripting language.
Ans: D
25. Choose the server-side JavaScript object?
A. FileUpLoad
B. Function
C. File
D. Date
Ans: C
26. Choose the client-side JavaScript object?
A. Database
B. Cursor
C. Client
D. FileUpLoad
Ans: D
27. Which of the following is not considered a JavaScript operator?
A. new
B. this
C. delete
D. typeof
Ans: B
28. ______method evaluates a string of JavaScript code in the context of the
specified object.
A. Eval
B. ParseInt
C. ParseFloat
D. Efloat
Ans: A
29. Which of the following event fires when the form element loses the focus:
<button>, <input>, <label>, <select>, <textarea>?
A. onfocus
B. onblur
C. onclick
D. ondblclick
Ans: B
30. The syntax of Eval is ________________
A. [objectName.]eval(numeriC.
B. [objectName.]eval(string)
C. [EvalName.]eval(string)
D. [EvalName.]eval(numeriC.
Ans: B
31. JavaScript is interpreted by _________
A. Client
B. Server
C. Object
D. None of the above
Ans: A
32. Using _______ statement is how you test for a specific condition.
A. Select
B. If
C. Switch
D. For
Ans: B
33. Which of the following is the structure of an if statement?
A. if (conditional expression is true) thenexecute this codeend if
B. if (conditional expression is true)execute this codeend if
C. if (conditional expression is true) {then execute this code>->}
D. if (conditional expression is true) then {execute this code}
Ans: C
34. How to create a Date object in JavaScript?
A. dateObjectName = new Date([parameters])
B. dateObjectName.new Date([parameters])
C. dateObjectName := new Date([parameters])
D. dateObjectName Date([parameters])
Ans: A
35. The _______ method of an Array object adds and/or removes elements from an
array.
A. Reverse
B. Shift
C. Slice
D. Splice
Ans: D
36. To set up the window to capture all Click events, we use which of the
following statement?
A. window.captureEvents(Event.CLICK);
B. window.handleEvents (Event.CLICK);
C. window.routeEvents(Event.CLICK );
D. window.raiseEvents(Event.CLICK );
Ans: A
37. Which tag(s) can handle mouse events in Netscape?
A. <IMG>
B. <A>
C. <BR>
D. None of the above
Ans: B
38. ____________ is the tainted property of a window object.
A. Pathname
B. Protocol
C. Defaultstatus
D. Host
Ans: C
39. To enable data tainting, the end user sets the _________ environment variable.
A. ENABLE_TAINT
B. MS_ENABLE_TAINT
C. NS_ENABLE_TAINT
D. ENABLE_TAINT_NS
Ans: C
40. In JavaScript, _________ is an object of the target language data type that
encloses an object of the source language.
A. a wrapper
B. a link
C. a cursor
D. a form
Ans: A
41. When a JavaScript object is sent to Java, the runtime engine creates a Java
wrapper of type ___________
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B
42. _______ class provides an interface for invoking JavaScript methods and
examining JavaScript properties.
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B
43. _________ is a wrapped Java array, accessed from within JavaScript code.
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: A
44. A ________ object is a reference to one of the classes in a Java package, such
as netscape.javascript .
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: B
45. The JavaScript exception is available to the Java code as an instance of
__________
A. netscape.javascript.JSObject
B. netscape.javascript.JSException
C. netscape.plugin.JSException
D. None of the above
Ans: B
46. To automatically open the console when a JavaScript error occurs which of the
following is added to prefs.js?
A. user_pref(" javascript.console.open_on_error", false);
B. user_pref("javascript.console.open_error ", true);
C. user_pref("javascript.console.open_error ", false);
D. user_pref("javascript.console.open_on_error", true);
Ans: D
47. To open a dialog box each time an error occurs, which of the following is
added to prefs.js?
A. user_pref("javascript.classic.error_alerts", true);
B. user_pref("javascript.classic.error_alerts ", false);
C. user_pref("javascript.console.open_on_error ", true);
D. user_pref("javascript.console.open_on_error ", false);
Ans: A
48. The syntax of a blur method in a button object is ______________
A. Blur()
B. Blur(contrast)
C. Blur(value)
D. Blur(depth)
Ans: A
49. The syntax of capture events method for document object is ______________
A. captureEvents()
B. captureEvents(args eventType)
C. captureEvents(eventType)
D. captureEvents(eventVal)
Ans: C
50. The syntax of close method for document object is ______________
A. Close(doC.
B. Close(object)
C. Close(val)
D. Close()
Ans: D
51. <script type="text/javascript"> x=4+"4"; document.write(x); </script>
Output------?
A. 44
B. 8
C. 4
D. Error output
Ans: A
52. Is it possible to nest functions in JavaScript?
A. True B. False
Ans: A
53. <script> document.write(navigator.appCodeName); </script>
A. get code name of the browser of a visitor
B. set code name of the browser of a visitor
C. None of the above
Ans: A
54. Scripting language are
A. High Level Programming language
B. Assembly Level programming language
C. Machine level programming language
Ans: A
55. Which best explains getSelection()?
A. Returns the VALUE of a selected OPTION.
B. Returns document.URL of the window in focus.
C. Returns the value of cursor-selected text
D. Returns the VALUE of a checked radio input.
Ans: C
56. Choose the client-side JavaScript object:
A. Database
B. Cursor
C. Client
D. FileUpLoad
Ans: D
57. What is mean by "this" keyword in javascript?
A. It refers current object
B. It referes previous object
C. It is variable which contains value
D. None of the above
Ans: A
58. In JavaScript, Window.prompt() method return true or false value ?
A. False B. True
Ans: A
59. <script language="javascript"> function x() { document.write(2+5+"8"); }
</script>
A. 258
B. Error
C. 7
D. 78
Ans: D
60. <script type="text/javascript"> var s = "9123456 or 80000?"; var pattern = /\
d{4}/; var output = s.match(pattern); document.write(output); </script>
A. 9123
B. 91234
C. 80000
D. None of the above
Ans: A
Javascript Quiz Questions and Answers-Sheet 2
1) <script type="text/javascript"> x=4+"4"; document.write(x); </script>
Output------?
a) 44
b) 8
c) 4
d) Error output
2) <script type="text/javascript" language="javascript">
var qpt = "Qualiyt Point Technologies";
var result = qpt.split(" ");
document.write(result);
</script>
a) Quality
b) Q,u,a,l,i,t,y,P,o,i,n,t,T,e,c,h,n,o,l,o,g,i,e,s
c) Qualiyt,Point,Technologies
d) QualityPointTechnologies
3) Is it possible to nest functions in JavaScript?
a) True
b) False
4) <script>
document.write(navigator.appCodeName);
< /script>
a) get code name of the browser of a visitor
b) set code name of the browser of a visitor
c) None of the above
5) 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.
6) Scripting language are
a) High Level Programming lan
b) Assembly Level programming language
c) Machine level programming language
Show Answer
7) Which best explains getSelection()?
a) Returns the VALUE of a selected OPTION.
b) Returns document.URL of the window in focus.
c) Returns the value of cursor-selected text
d) Returns the VALUE of a checked radio input.
8) <script language="javascript">
function x()
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error
9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error
10) Choose the client-side JavaScript object:
a) Database
b) Cursor
c) Client
d) FileUpLoad
11) Are java and javascript the same?
a) NO
b) YES
12) Syntax for creating a RegExp object:
(a). var txt=new RegExp(pattern,attributes);
(b). var txt=/pattern/attributes;
Which of the above mentioned syntax will correct?
a) (a) only
b) (b) only
c) Both (a) and (b)
d) None of the above
13) <script language="javascript">
function x(z,t)
alert(x.length);
< /script>
output:
?
a) Error
b) 2
c) 1
d) 3
14) What is mean by "this" keyword in javascript?
a) It refers current object
b) It referes previous object
c) It is variable which contains value
d) None of the above
15) In JavaScript, Window.prompt() method return true or false value ?
a) False
b) True
c) None of above
16) Math. round(-20.51)=?
a) 20
b) -21
c) 19
d) None
17) <script language="javascript"> function x() { var s = "Quality 100%!{[!!"; var
pattern = /\w/g; var output = s.match(pattern); document.write(output); } </script>
a) %,!,{,[,!,!
b) Q,u,a,l,i,t,y,1,0,0
c) Quality 100
d) Error
18) <script type="text/javascript" language="javascript">
var qpt= new Array();
qpt[0] = "WebDevelopment";
qpt[1]="ApplicationDevelopment"
qpt[2]="Testing"
qpt[3] = "QualityPointTechnologies";
document.write(qpt[0,1,2,3]);
</script>
a) Error
b) QualityPointTechnologies
c) WebDevelopment
d) WebDevelopmnet,ApplicationDevelopment,Testing,QualityPointTechnologies
19) Choose the server-side JavaScript object:
a) FileUpLoad
b) Function
c) File
d) Date
20) parseFloat(9+10)=?
a) 19
b) 910
c) None
21) <script language="javascript">
function x()
{
document.write(2+5+"8");
</script>
a) 258
b) Error
c) 7
d) 78
22)_________ keyword is used to declare variables in javascript.
a) Var
b) Dim
c) String
23) In Javascript, Which of the following method is used to evaluate the regular
expression?
a) eval(2*(3+5))
b) evaluate(2*(3+5))
c) evalu(2*(3+5))
d) None of the above
24) <script language="javascript">
function x()
var s= "quality 100%";
var pattern = /\d/g;
var output= s.match(pattern);
document.write(output);
</script>
a) 100
b) 1,0,0
c) q,u,a,l,i,t,y,%
d) Error
25) <script type="text/javascript" language="javascript">
qpt=((45%2)==0)? "hello" : "bye";
document.write(qpt);
</script>
a) hello
b) bye
c) Error in string handling
d) None of the above
26)<script language="javascript"> function x() { var qpt =
"QualityPointTechnologies"; var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern)); } </script>
a) Error
b) POIiNT
c) Point
d) null
27) How do you create a new object in JavaScript?
a) var obj = {};
b) var obj = Object();
c) var obj=new {};
d) None of the above
28) In Javascript, What does isNaN function do ?
a) Return true if the argument is not a number.
b) Return false if the argument is not a number.
c) Return true if the argument is a number.
d) None of the above
29) If x=103 & y=9 then x%=y , what is the value of x after executing x%=y?
a) 4
b) 3
c) 2
d) 5
30) Choose the external object:
a) Date
b) Option
c) Layer
d) Checkbox
31) Choose the four symbol pairs that represent RegExp properties lastMatch,
lastParent,
leftContext, and rightContext, respectively:
a) $&, $+, $`, $'
b) $+, $&, $', $`
c) $&, $~, $`, $'
d) $+, $&, $`, $'
32) Which of the following properties hold the values of the pixels of the length of
the width
and height of the viewer's screen resolution?
a) screen.width and screen.height
b) Resolution.width and Resolution.height
c) screen.pixels.width and screen.pixels.height
d) ViewerScreen.width and ViewerScreen.height
33) ParseInt(“15”,10)=?
a) 15
b) 10
c) 151
d) 150
34) Which JavaScript feature uses JAR files?
a) Object signing
b) Style sheets
c) Netcaster channels
d) Image rollovers
35)How to assign a function to a variable with the JavaScript Function contructor ?
a) var f=Function("x","y","return x+y");
b) var f=Function(x,y){ return x+y;}
c) var f= new Function("x", "y", "return x + y");
36) In JavaScript, Window.alert() is used to allow user to enter something
a) True
b) False
c) None of above
37) <script language="javascript">
function x()
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","gi");
document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " ");
} </script>
a) in in In
b) in in in
c) in in null
d) in null null
38) Is Javascript has any date data type?
a) Yes
b) No
39) Math. round(-20.5)=?
a) -21
b) 20
c) -20
d) 21
40) ?_name is it valid javascript identifier?
a) Yes
b) No
41) <script language="javascript">
function x()
var qpt = "First come, first served";
var pattern = /first/gi;
document.write(qpt.match(pattern)[1]);
</script>
a) first
b) undefined
c) First
d) Error
42) (a). // , /* ...... **/
(b). / , /** ......./ , /*
(c). /*......*/ , //
(d). \*......*\ , //
In javascript, Which of the above Comments lines are used ?
a) Only (d)
b) Only (c)
c) Either (c) or (d)
d) Only (b)
43) <script language="javascript">
function x()
{
var s = "Give 100%!{[!!";
var pattern = /\W/g;
var output = s.match(pattern);
document.write(output);
</script>
a) ,%,!,{,[,!,!
b) G,i,v,e,1,0,0
c) Give 100
d) Error
44) Which best describes void?
a) A method
b) A function
c) A statement
d) An operator
45) <script type="text/javascript" language="javascript">
var qpt="QualityPointTechnologies";
var result =qpt.lastIndexOf("l");
document.write(result);
</script>
a) 3
b) 18
c) 17
d) 19
46) <script language="javascript">
function x()
var qpt = "First come, first served";
var pattern = /first/g;
document.write(qpt.match(pattern)[1]);
</script>
a) first
b) First
c) undefined
d) None of the above
47) <script language="javascript">
function sum(x)
function add(y)
return x+y;
return add;
function callme() { result=sum(5)(5); alert(result); }
</script>
If you call the function callme(), what will happen ?
a) 10
b) Error in calling Function
c) 5
d) None of the above
48) Who invented the javascript programming language?
a) Tennis Ritchie
b) James Gosling
c) Brendan Eich
49) <script type="text/javascript">
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
</script>
Can you write HTML tag inside the javascript ?
a) No
b) Yes
c) Impossible
50) Which feature is supported in MSIE 3.x?
a) split()
b) document.clear()
c) join()
d) charAt()
51) How to speicfy the color of the hypertext links with JavaScript ?
a) document.linkColor="#00FF00";
b) document.LColor="#00FF00";
c) document.LinkC="#00FF00";
d) document.hyperTextLink="#00FF00":
52) <script language="javascript">
function x()
var qpt = "QualityPointTechnologies";
var pattern = /point/;
var output= qpt.search(pattern);
document.write("Position: " + output);
</script>
a) Position-7
b) Position-1
c) null
d) error
53) --------------- method returns the number of milliseconds in a date string.
a) setHours()
b) setMinutes()
c) parse()
54) ------------- converts a string to floating point numbers.
a) eval
b) ParseInt
c) ParseFloat
d) None
55) ---------------------- attempts to evaluate a string representing any javascript
literals or
variables, converting it to a number.
a) eval
b) parseFloat
c) parseInt
d) None
56) Which is not an attribute of the
a) path
b) host
c) secure
d) domain
57) How do substring() and substr() differ?
a) One is not a method of the String object.
b) substr() takes three arguments, substring() only two.
c) Only one accepts a desired string length as an argument.
d) Besides the spelling, nothing.
58) Which is not a reserved word?
a) interface
b) short
c) program
d) throws
59) In Javascript, Which of the following method is used to find out the character
at a
position in a string?
a) charAt()
b) CharacterAt()
c) CharPos()
d) characAt()
60) <script type="text/javascript" language="javascript">
var qpt = "QualityPointTechnologies";
var result =qpt.substring(7,8);
document.write(result);
</script>
a) Po
b) yP
c) oi
d) P
61) How do you delete an element from an options array?
a) Set it to false.
b) Set it to null.
c) Set it to undefined.
d) Set it to -1
62) Is javaScript case sensitive ?
a) Yes
b) No
63) JavaScript RegExp Object has modifier 'i' to __________
a) Perform case-sensitive matching
b) Perform case-insensitive matching
c) Perform both case-sensitive&case-insensitive matching
64) What are the following looping structures are available in javascripts?
a) for,forecach
b) foreach,whileloop
c) do-while loop,foreach
d) for , while loop
65) Which of these is not a method of the Math object?
a) atan()
b) atan2()
c) eval()
d) acos()
66) <script type="text/javascript">
var s = "9123456 or 80000?";
var pattern = /\d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
a) 9123
b) 91234
c) 80000
d) None of the above
67) In javascript, RegExp Object Method test() is used to search a string and
returns
_________
a) true or false
b) found value
c) index
d) None of the above
68) What property would you use to redirect a visitor to another page?
a) document.URL
b) window.location.href
c) .document.location.href
d) link.href
69) a.) var qpt="Quality Point Technologies";
b.) var qpt=new String("Quality Point Technologies");
Question:
In javascript, which of the above statement can used for string declaration ?
a) Either (a) or (b)
b) Only (a)
c) Neither (a) nor (b)
d) Only (b)
70) <script type="text/javascript" language="javascript">
var qpt = "QualityPointTechnologies";
var result =qpt.indexOf("Tech");
document.write(result);
</script>
a) 11
b) 12
c) 15
d) 13
71) <script language="javascript">
function x()
var s = "Eat to live, but do not live to eat";
var pattern = new RegExp("eat$");
document.write(pattern.exec(s));
</script>
a) Eat
b) eat
c) undefined
d) Eat eat
72) <script language="javascript">
function x()
var qpt = "We are fast growing Software Company located in Chennai, India.";
var pattern = new RegExp("in","g"); document.write(pattern.exec(qpt) + " ");
document.write(pattern.exec(qpt) + " "); document.write(pattern.exec(qpt) + " "); }
</script>
a) in in In
b) in in in
c) in in null
d) in null null
73) -------------- method is used to remove focus from the specified object.
a) blur()
b) focus()
c) None
74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer
75)eval((20*4)=?
a) Nan
b) 204
c) 24
d) 80
76)<script language="javascript">
function x()
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("TECHNOLOGIES","i");
document.write(qpt.match(pattern));
}
</script>
a) null
b) Technologies
c) TECHNOLOGIES
d) Error
77)Javascript is a ________ typed language.
a) tightly
b) loosely