Question-1: Analyze the following
code snippet. What will be the output of this code?
<html>
<body>
<script type="text/javascript">
var str = "The drain of the plane is plain";
var patt1 =/ain/g;
document. Write(str.match(patt1));
</script>
</body>
</html>
a. 1
b.
ain
c.
7,29
d. 7
Answer : e. ain,ain
Question-2: Which of the
following is the correct syntactical representation of a generator expression
in JavaScript?
a.
var doubles = [i * 2 for (i in it)];
b.
var doubles = [i * 2 for [i in it]];
Answer: c. var doubles = (i * 2 for (i in it));
d.
var doubles = {i * 2 for (i in it)};
Question-3: What is the output of
the following JavaScript code?
s2 = new String("2 + 2")
document.write(eval(s2));
s2 = new String("2 + 2")
document.write(eval(s2));
a. 4
Answer : b. 2+2
c.
Error
d.
None of the above
Question-4: Consider the
following code snippet. Which of the given options would be used in E4X to
change the color of the descendant node chair?
var element = <Home>
<Room>
<Furniture>
<chair color="Brown"/>
</Furniture>
</Room>
</Home>
var element = <Home>
<Room>
<Furniture>
<chair color="Brown"/>
</Furniture>
</Room>
</Home>
Answer : a. element.chair.color="light brown"
b.
element.chair.@color="light brown"
c.
element..chair.@color="light brown"
Question-5: Consider the code
snippet below. Which of the given options represents the correct sequence of
outputs when this code is executed in E4X?
var p1 = <p>Kibology for all.</p>;
alert(p1.name().uri);
default xml namespace = 'http://www.w3.org/1999/xhtml';
var p2 = <p>Kibology for all.</p>;
alert(p2.name().uri);
default xml namespace = '';
var p3 = <p>Kibology for all.</p>;
alert(p3.name().uri);
var p1 = <p>Kibology for all.</p>;
alert(p1.name().uri);
default xml namespace = 'http://www.w3.org/1999/xhtml';
var p2 = <p>Kibology for all.</p>;
alert(p2.name().uri);
default xml namespace = '';
var p3 = <p>Kibology for all.</p>;
alert(p3.name().uri);
a.
'',http://www.w3.org/1999/xhtml,''
b.
'','',''
Answer : d. None of the above
Question-6: Which of the
following is not a valid JavaScript operator?
a.
*=
b.
/=
c.
%=
Answer : d. ^+
Question-7: Which of the
following is not a valid String method?
a.
link()
b.
italics()
Answer : c. str()
d.
sup()
Question-8: Which of the
following methods is used to add and/or remove elements from an array and
modify them in place?
a.
push
b.
slice
c.
join
Answer : d. splice
Question-9: In JavaScript, the
encodeURI() function is used to encode special characters. Which of the following
special characters is/are an exception to that rule?
a. £
b. €
c. @
d. $
Answer : e. a and b
f. c
and d
Question-10: Which of the
following is not a valid Date Object method in JavaScript?
a.
parse()
b.
setDay()
Answer : c. setTime()
d.
valueOf()
Question: Which of the
following results is returned by the JavaScript operator "typeof" for
the keyword "null"?
a.
function
Answer : b. object
c.
string
d.
number
Question: Which of the
following can be used to create attribute values by placing variables and
expressions within them?
a.
[]
b.
()
c.
{}
Answer : d. <>
Question: What will the
function NaN return for the condition NaN == NaN?
a.
true
Answer : b. false
c.
error
d. 0
Question: Which of the
following modifiers must be set if we use the Javascript lastIndex Object
Property during pattern matching?
a. i
b. m
c. g
Answer : d. s
Question:Which of the following
two JavaScript code snippets is the more efficient and why?
CODE SNIPPET 1
<script language="javascript">
for(i=0;i<document.images.length;i++)
document.images[i].src="blank.gif";
</script>
CODE SNIPPET 2
<script language="javascript">
var theimages = document.images;
for(i=0;i<theimages.length;i++)
theimages[i].src="blank.gif";
</script>
CODE SNIPPET 1
<script language="javascript">
for(i=0;i<document.images.length;i++)
document.images[i].src="blank.gif";
</script>
CODE SNIPPET 2
<script language="javascript">
var theimages = document.images;
for(i=0;i<theimages.length;i++)
theimages[i].src="blank.gif";
</script>
a.
Both codes are equally efficient.
b.
The first code is more efficient because it contains less code.
c.
The first code is more efficient because it employs object caching.
Answer : d. The second code is more efficient because it employs object
caching.
Question:Which of the following is
used to solve the problem of enumerations in JavaScript?
a.
let
b.
Regex
Answer : c. Generators
d.
E4X
Question:Is the following
statement regarding expression closures in JavaScript true or false?
The syntax function(x) {return x*x;} can be written as function(x) x*x.
The syntax function(x) {return x*x;} can be written as function(x) x*x.
a.
True
Answer : b. False
Question:Which of the given
options represents the correct length when alert(Emp..*.length()); is applied
to the following code?
var Emp = <Emp>
<name>Mark</name>
<likes>
<os>Linux</os>
<browser>Firefox</browser>
<language>JavaScript</language>
<language>Python</language>
</likes>
</Emp>
var Emp = <Emp>
<name>Mark</name>
<likes>
<os>Linux</os>
<browser>Firefox</browser>
<language>JavaScript</language>
<language>Python</language>
</likes>
</Emp>
Answer : a. 11
b. 5
c. 6
d.
12
Question:Analyze the following
code snippet. What will be the output of this code?
<html>
<body>
<script type="text/javascript">
var str = "Visit Gardens(now)";
var patt1 = new RegExp("(now)", "g");
patt1.test(str);
document.write(RegExp.lastParen);
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
var str = "Visit Gardens(now)";
var patt1 = new RegExp("(now)", "g");
patt1.test(str);
document.write(RegExp.lastParen);
</script>
</body>
</html>
Answer : a. now
b.
(now)
c.
15
d.
19
Question:Which of the following is
the correct way to create an XML object in E4X?
a.
var languages = new XML('JavaScriptPython');
b.
var languages XML = new XML('JavaScriptPython');
c.
var languages =
JavaScript
Python
;
JavaScript
Python
;
d.
All of the above are correct.
Answer : e. a and c
f. b
and c
Question:Which of the following
Array methods in JavaScript runs a function on every item in the Array and
collects the result from previous calls, but in reverse?
a.
reduce()
b.
reduceRight()
Answer : c. reverse()
d.
pop()
Question:Which of the following
can be achieved using JavaScript?
a.
Reading or writing from external files
b.
Accessing or modifying browser settings
c.
Launching the default email application of the client
Answer : d. All of the above can be achieved using JavaScript.
Question:Which of the following
objects is the top-level object in the JavaScript hierarchy?
a.
Navigator
b.
Screen
Answer : c. Window
d.
Document
Question:Which of the following
Javascript Regular Expression modifiers finds one or more occurrences of a
specific character in a string?
Answer : a. ?
b. *
c. +
d. #
Question:Which of the following is
the correct syntax for using the Javascript exec() object method?
a.
RegExpObject.exec()
Answer : b. RegExpObject.exec(string)
c.
RegExpObject.exec(parameter1,parameter2)
d.
None of the above
Question:Analyze the following
code using the source property of Regular Expressions. What will be the output
of the below code snippet?
<html>
<body>
<script type="text/javascript">
var str = "Visit Garden\Showcase";
var patt1 = new RegExp("en\S","g");
document.write("The regular expression is: " + patt1.source);
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
var str = "Visit Garden\Showcase";
var patt1 = new RegExp("en\S","g");
document.write("The regular expression is: " + patt1.source);
</script>
</body>
</html>
a.
The regular expression is: en\S
b.
The regular expression is: 11
Answer : c. The regular expression is: enS
d.
The regular expression is: 10
Question:Which of the following
options can be used for adding direct support for XML to JavaScript?
Answer : a. E4X
b.
regex
c.
Generators and Iterators
d.
let
Question:Which of the following
options is used to access the attributes in E4X?
Answer : a. @
b.
::
c. #
d. *
Question:Which of the following
statements regarding let in JavaScript is not correct?
a.
The let definition defines variables whose scope is constrained to the block in
which they're defined. This syntax is very much like the syntax used for var.
b.
The let expression lets you establish variables scoped only to a single
expression.
Answer : c. The let keyword provides a way to associate values with
variables within the scope of a block, and affects the values of like-named
variables outside the block.
d.
You can use let to establish variables that exist only within the context of a
for loop.
Question:Which of the following
are not global methods and properties in E4X?
a.
ignoreComments
b.
ignoreWhiteSpace
c.
setName()
d.
setNamespace()
e. a
and b
Answer : f. c and d
Question:What will be the output
of the following code?
var x = 5;
var y = 0;
document.write( let(x = x + 10, y = 12) x+y + ",");
document.write(x+y);
var x = 5;
var y = 0;
document.write( let(x = x + 10, y = 12) x+y + ",");
document.write(x+y);
Answer : a. 27,5
b.
22,5
c.
27,22
d.
None of the above
Answer : a. send()
b.
throw()
c.
next()
d.
stop()
Question:Using the concept of
"iterators" and "generators" in JavaScript, what will be
the output of the following code?
function testGenerator()
{
yield "first";
document.write("step1");
yield "second";
document.write("step2");
yield "third";
document.write("step3");
}
var g = testGenerator();
document.write(g.next());
document.write(g.next());
function testGenerator()
{
yield "first";
document.write("step1");
yield "second";
document.write("step2");
yield "third";
document.write("step3");
}
var g = testGenerator();
document.write(g.next());
document.write(g.next());
a.
firststep1second
b.
step1step2
Answer : c. step1
d.
step1step2step3
Question:Which of the following
DOM objects can be used to determine the resolution of the screen?
a.
It is not possible to determine the resolution of the screen.
Answer : b. Screen object
c.
Document object
d.
Window object
e.
None of the above
Question:Analyze the following
code snippet. What will be the output of this code?
<html>
<body>
<script type="text/javascript">
var str = "The rose";
var patt1 = new RegExp("rose", "g");
patt1.test(str);
document.write("rose found. index now at: " + patt1.lastIndex);
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
var str = "The rose";
var patt1 = new RegExp("rose", "g");
patt1.test(str);
document.write("rose found. index now at: " + patt1.lastIndex);
</script>
</body>
</html>
a.
rose found. index now at: 5
b.
rose found. index now at: 4
Answer : c. rose found. index now at: 8
d.
No output
Question:Which of the following
options can be used to delete a child node of an XML object in E4X?
a.
delete xmlobject.child;
b.
delete xmlobject.child[0];
c.
delete xmlobject.@attribute;
Answer : d. All of the above
Question:Analyze the following
code snippet, which uses a Javascript Regular Expression Character Set. What
will be the output of this code?
<html>
<body>
<script type="text/javascript">
var str = "Is this enough?";
var patt1 = new RegExp("[^A-J]");
var result = str.match(patt1);
document.write(result);
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
var str = "Is this enough?";
var patt1 = new RegExp("[^A-J]");
var result = str.match(patt1);
document.write(result);
</script>
</body>
</html>
Answer : a. I
b.
Is
c. s
d.
I,s,
Question:Consider the code below.
What will be the final value of the variable "apt"?
var apt=2;
apt=apt<<2;
var apt=2;
apt=apt<<2;
a. 2
b. 4
c. 6
Answer : d. 8
e.
16
Question:Is the following
statement true or false?
A function becomes a generator if it contains one or more yield statements.
A function becomes a generator if it contains one or more yield statements.
Answer : a. True
b.
False
Question:What does the following
JavaScript code do?
<html>
<body>
<script type="text/javascript">
function validate()
{
var chk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var ok="yes";
var temp;
var field1=document.getElementById("t1");
var field=field1.value.substring(field1.value.length-1,field1.value.length);
if(chk.indexOf(field)=="-1")
{
alert("error");
field1.value=(field1.value).slice(0,field1.value.length-1);
}
}
</script>
<input type="text" id="t1" onkeyup="validate()" onkeypress ="validate()"/>
</body>
</html>
<html>
<body>
<script type="text/javascript">
function validate()
{
var chk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var ok="yes";
var temp;
var field1=document.getElementById("t1");
var field=field1.value.substring(field1.value.length-1,field1.value.length);
if(chk.indexOf(field)=="-1")
{
alert("error");
field1.value=(field1.value).slice(0,field1.value.length-1);
}
}
</script>
<input type="text" id="t1" onkeyup="validate()" onkeypress ="validate()"/>
</body>
</html>
Answer : a. The code will cause an error alert to be displayed if a
numeric character is entered, and the numeric character is removed.
b.
The code will cause an error alert to be displayed if a non-numeric character
is entered, and the non-numeric character is removed.
c.
The code will cause an error alert to be displayed if a numeric character is
entered, and the value of textbox is reset.
d.
The code will cause an error alert to be displayed if a non-numeric character
is entered, and the value of textbox is reset.
Question:Analyze the following
code snippet. What will be the output of this code?
<html>
<body>
<script type="text/javascript">
var str = "Visit Gardens(now)";
var patt1 = new RegExp("(now)", "g");
patt1.test(str);
document.write(RegExp.lastParen);
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
var str = "Visit Gardens(now)";
var patt1 = new RegExp("(now)", "g");
patt1.test(str);
document.write(RegExp.lastParen);
</script>
</body>
</html>
Answer : a. no
b.
(no)
c.
15
d.
19
Question:Which of the following is
the correct method for getting the date of February 1 of the current year into
a variable called "newDate"?
a.
var d = new Date();
newDate=new Date(d.getFullYear(), 1, 2);
newDate=new Date(d.getFullYear(), 1, 2);
b.
var d = new Date();
newDate=new Date(d.getFullYear(), 2, 1);
newDate=new Date(d.getFullYear(), 2, 1);
Answer : c. var d = new Date();
newDate=new Date(d.getFullYear(), 1, 1);
newDate=new Date(d.getFullYear(), 1, 1);
d.
var d = new Date();
newDate= (d.getFullYear(), 1, 1);
newDate= (d.getFullYear(), 1, 1);
Question:Which of the following
can be used to create attribute values by placing variables and expressions
within them?
a.
[]
b.
()
Answer : c. {}
d.
<>
Question:Which of the
following Javascript Regular Expression Character
Classes finds any non-digit character in a given string?
a.
\W
b.
\S
c.
\B
Answer : d. \D
Question:Which of the following
objects in JavaScript contains the collection called "plugins"?
a.
Location
Answer : b. Window
c.
Screen
d.
Navigator
Question:Which of the following
Javascript Regular Expression object methods is used to search a string for a
specified value and return the result as true or false?
a.
exec()
b.
compile()
c.
return()
Answer : d. test()
Question:Which of the following
methods is not a valid Array object method in JavaScript?
a.
reverse
b.
shift
c.
unshift
d.
splice
Answer : e. All of the above are valid.
Question:In an HTML page, the form
tag is defined as follows:
<form onsubmit="return Validate()" action="http://www.mysite.com/">
The validate() function is intended to prevent the form from being submitted if the name field in the form is empty. What will the validate() function look like?
<form onsubmit="return Validate()" action="http://www.mysite.com/">
The validate() function is intended to prevent the form from being submitted if the name field in the form is empty. What will the validate() function look like?
a.
<script type="text/javascript">
function Validate()
{
if(document.forms[0].name.value == "")
return true;
else
return false;}
</script>
function Validate()
{
if(document.forms[0].name.value == "")
return true;
else
return false;}
</script>
b.
<script type="text/javascript">
function Validate()
{
if(document.forms[0].name.value == "")
return false;
else
return true;
}
</script>
function Validate()
{
if(document.forms[0].name.value == "")
return false;
else
return true;
}
</script>
c.
<script type="text/javascript">
function Validate()
{
if(document.forms[0].name== "")
return false;
else
return true;
}
</script>
function Validate()
{
if(document.forms[0].name== "")
return false;
else
return true;
}
</script>
Answer : d. <script type="text/javascript">
function Validate()
{
if(document.forms[0].name == "")
return true;
else
return false;
}
</script>
function Validate()
{
if(document.forms[0].name == "")
return true;
else
return false;
}
</script>
Question:Which of the following is
the correct way to create an XML object in E4X?
a.
var languages = new XML('<languages
type="dynamic"><lang>JavaScript</lang><lang>Python</lang></languages>');
b.
var languages XML = new XML('<languages
type="dynamic"><lang>JavaScript</lang><lang>Python</lang></languages>');
c.
var languages = <languages type="dynamic">
<lang>JavaScript</lang>
<lang>Python</lang>
</languages>;
<lang>JavaScript</lang>
<lang>Python</lang>
</languages>;
d.
All of the above are correct.
Answer : e. a and c
f. b
and c
Question:What does the following
JavaScript code do? <head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function validate() {
var chk = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var ok = "yes";
var temp;
var field1 = document.getElementById("t1");
var field = field1.value.substring(field1.value.length - 1, field1.value.length);
if (chk.indexOf(field) == "-1") {
alert("error");
field1.value = (field1.value).slice(0, field1.value.length - 1);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="t1" onkeyup="validate()" onkeypress ="validate()"/>
</form>
</body>
<script type="text/javascript">
function validate() {
var chk = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var ok = "yes";
var temp;
var field1 = document.getElementById("t1");
var field = field1.value.substring(field1.value.length - 1, field1.value.length);
if (chk.indexOf(field) == "-1") {
alert("error");
field1.value = (field1.value).slice(0, field1.value.length - 1);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="t1" onkeyup="validate()" onkeypress ="validate()"/>
</form>
</body>
Answer : a. The code will cause an
error alert to be displayed if a non alphabet character is entered.
b.
The code will cause an error alert to be displayed if ALPHABET character is
entered.
c.
The code will cause NO error alert to be displayed if a numeric character is
entered.
d. The code will cause NO
error alert to be displayed if a NON ALPHABET character is entered.