1. Consider the following JavaScript alert:
<script type=»text/JavaScript»>
function message() {
alert(«Welcome to ExpertRating!!!»)
}
</script>
Which of the following will run the function when a user opens the page?
body onload=»message()»
body onunload=»message()»
body onsubmit=»message()»
body onreset=»message()»
2. Which of the following is not a valid method in generator-iterator objects in JavaScript?
send()
throw()
next()
stop()
3. How can created cookies be deleted using JavaScript?
They can’t be deleted. They are valid until they expire.
Overwrite with an expiry date in the past
Use escape() on the value of the path attribute
Use unescape() on the value of the path attribute
The cookie file will have to be removed from the client machine.
Wait till the expiry date is reached
4. Which of the following JavaScript Regular Expression modifiers finds one or more occurrences of a specific character in a string?
?
*
+
#
5. Which of the following is not a valid Date Object method in JavaScript?
parse()
setDay()
setTime()
valueOf()
6. 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?
reduce()
reduceRight()
reverse()
pop()
7. When setting cookies with JavaScript, what will happen to the cookies.txt data if the file exceeds the maximum size?
The script automatically generates a run-time error.
The script automatically generates a load-time error.
All processes using document.cookie are ignored.
The file is truncated to the maximum length.
8. Which of the following can be used for disabling the right click event in Internet Explorer?
event.button == 2
event.button == 4
event.click == 2
event.click == 4
9. Which of the following code snippets will toggle a div element’s background color?
<button id=»toggle»>Toggle</button>
<div id=»terd»>Change Background Color.</div>
<script> var button = document.getElementById(‘toggle’);
button.click = function() { terd.style.backgroundColor = terd.style.backgroundColor == ‘blue’ ? ‘red’ :
‘blue’; }; </script>
<script> var button = document.getElementById(‘toggle’); button.ready = function() {
terd.style.backgroundColor = terd.style.backgroundColor == ‘blue’ ? ‘red’ : ‘blue’; };
</script>
<script> var button = document.getElementById(‘toggle’); button.focus = function() {
terd.style.backgroundColor = terd.style.backgroundColor == ‘blue’ ? ‘red’ : ‘blue’; };
</script>
<script> var button = document.getElementById(‘toggle’); button.onclick = function() { terd.style.backgroundColor = terd.style.backgroundColor == ‘blue’ ? ‘red’ : ‘blue’; }; </script>
10. Consider the following JavaScript validation function:
function ValidateField()
{
if(document.forms[0].txtId.value ==»»)
{return false;}
return true;
}
Which of the following options will call the function as soon as the user leaves the field?
input name=txtId type=»text» onreset=»return
ValidateField()»
input name=txtId type=»text» onfocus=»return ValidateField()»
input name=txtId type=»text» onsubmit=»return ValidateField()»
input name=txtId type=»text» onblur=»return ValidateField()»
11. What will be 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());
firststep1second
step1step2
step1
step1step2step3
12. Consider the following image definition:
<img id=»logo» src=»companylogo1.gif» height=»12″ width=»12″ >
Which of the following will change the image to companylogo2.gif when the page loads?
logo.source=»companylogo2.gif»
logo.source=»companylogo1.gif»
document.getElementById(‘logo’).src=»companylogo1.gif»
document.getElementById(‘logo’).src=»companylogo2.gif»
13. Which of the following are correct values of variableC, and why?
<script>
variableA = [6,8];
variableB =[7,9];
variableC = variableA + variableB;
</script>
6, 7, 8 and 9. The + operator is defined for arrays, and it
concatenates strings, so it converts the arrays to strings.
6, 15 and 9. The + operator is defined for arrays, and it concatenates numbers, so it converts
the arrays to numbers.
6, 8, 7 and 9. The + operator is defined for arrays, and it concatenates strings, so it converts
the arrays to strings.
6, 87 and 9. The + operator is not defined
for arrays,
and it concatenates strings, so it converts the arrays to strings.
14. Which of the following determines whether cookies are enabled in a browser or not?
(navigator.Cookie)? true : false
(application.cookieEnabled)? true : false
(navigator.cookieEnabled)? true : false
(application.cookie)? true : false
15. Which of the following modifiers must be set if the JavaScript lastIndex object property was used during pattern matching?
i
m
g
s
16. An image tag is defined as follows:
<img id=»ERImage» width=»100″ height=»100″ onmouseover=»ImageChange()» src=»Image1.jpg»>
The purpose of the ImageChange() function is to change the image source to Image2.jpg. Which of the following should the ImageChange() function look like?
document.getElementById(‘ERImage’).src=»Image1.jpg»
document.getElementById(‘ERImage’).src=»Image2.jpg»
document.getElementById(‘ERImage’).style.src=»Image1.jpg»
document.getElementById(‘ERImage’).style.src=»Image2.jpg»
17. Which of the following is true about setTimeOut()?
The statement(s) it executes run(s) only once.
It pauses the script in which it is called.
clearTimeOut() won’t stop its execution.
The delay is measured in hundredths of a second.
It is required in every JavaScript function.
18. Which of the following objects in JavaScript contains the collection called «plugins»?
Location
Window
Screen
Navigator
19. Which of following uses the «with» statement in JavaScript correctly?
with (document.getElementById(«blah»).style) { background = «black»; color = «blue»; border = «1px solid green»; }
with document.getElementById(«blah»).style background = «black»; color = «blue»; border = «1px
solid green»; End With
With document.getElementByName(«blah»).style background = «black»; color = «blue»; border = «1px
solid green»; End With
with (document.getElementById(«blah»).style) { .background = «black»; .color = «blue»; .border =
«1px solid green»; }
20. Which event can detect when the user highlights text within a text or textarea object?
onSelect
onBlur
onChange
onMove
None of these
21. Consider the following code snippet:
var myJSONObject =
{«ircEvent»: «PRIVMSG», «method»: «newURI», «regex»: «^http://.*»};
What is the best way to remove the property ‘regex’, so the result would be this code snippet?
myJSONObject ==
{«ircEvent»: «PRIVMSG», «method»: «newURI»};
myJSONObject.regex.delete;
myJSONObject.regex.remove;
delete myJSONObject.regex;
remove myJSONObject.regex;
22.Which of the following is the best way to show both single and double quotes in the same sentence?
alert(«It’s «+'»game»‘+» time.»);
alert(‘It\’s \»game\» time.’);
alert(‘It\’\s «game» time.’);
alert(‘It\’s «game» time.’);
23. Which of the following statements is true regarding importing JavaScript files inside of other JavaScript files?
There is no import/include/require keyword in JavaScript, but there
ways to import JS files inside of other JS files.
There is an import keyword in JavaScript, which
allows importing JS files inside of other JS
files.
There is no option to do so in JavaScript.
24. Which of the following shortcuts can be used for writing multiple document.write statements?
for(document){}
with(document) {}
withThis(document){}
None of these
25. 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. $
A
B
C
D
A and B
C and D
26. Consider the following code:
<form>
<textarea id=»foo» name=»foo»></textarea>
</form>
Which of the following is the best method to get the line number of the form’s text area?
<script> foo.value.split(/\r\n\|\r\|\n/g);
</script>
<script> foo.value.split(/\r\/n\|\r\|\n/g); </script>
<script> foo.value.split(/\rn\|\r\|\n/g); </script>
<script> foo.value.split(/\r\n|\r|\n/g);
</script>
27. Which of the following code snippets shows an alert for an empty string?
var a = «»;
If(a){ alert(‘This is empty string’);}
If(a == NUL){ alert(‘This is empty string’);}
If(!a){ alert(‘This is empty
string’);}
If(a.empty){ alert(‘This is empty string’);}
28. Consider the following code:
var setter=new Object()
setter.color=»blue»
How would you delete the color property of the variable seter?
setter.color delete;
delete setter.color
delete(setter.color)
setter.color.delete
29. 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.
True
False
30. Which of the following statements regarding this String prototype is correct?
String.prototype.doSomething = function(suffix) {
return this.indexOf(suffix, this.length — suffix.length) !== -1;
};
This method determines
whether or not a string ends with another
string.
This method determines whether or not a string begins with another string.
This method returns the position of the last occurrence of a specified value in a
string.
This method returns the position of the first occurrence of a specified value in a
string.
31. What will be the result of the following code?
document.getElementById(“banana”).className = document.getElementById(“banana”).className.replace(/(?:^|\s)apple(?!\S)/g ,’e’ );
Replace class ‘apple’ with ‘g’ in the HTML element which contains ID
‘banana’
Replace current class with ‘apple’ in the HTML element which contains ID ‘banana’
Replace class ‘apple’ with ‘e’ in the HTML element
which contains ID ‘banana’
Replace ID ‘apple’ with ‘banana’ in the HTML element which contains ID ‘banana’ and class
‘g’
32. Which of the following will determine if the user’s browser is named “Netscape”?
if(appName==”Netscape”){}
if(document.appName==”Netscape”){}
if(navigator==”Netscape”){}
if(browser==”Netscape”){}
None of these
33. Given a p element with some text content, which of the following code snippets sets the background color of the text to yellow, its color to red, and its font size to 20px?
var p = document.getElementById(elementId);
p.setAttribute(«style», «background-color:yellow;color:red;font-size:20px;»);
var p = document.getElementById(elementId);
p.style.background = ‘yellow’;
p.style.color= ‘red’;
p.style.size= ’20px’;
var p = document.getElementById(elementId);
p.style.background = ‘yellow’;
p.style.color= ‘red’;
p.style.font.size= ’20px’;
var p = document.getElementById(elementId);
p.setAttribute(«style», «background-color:red;color:yellow;font-size:20;»);
34. Which of the following are not valid HTML events?
onmouseover
onmouseout
onmouseabove
onmousedown
onmousein
35. Which of the following options is used to access the attributes in E4X?
@
::
#
*
36. Which of the following can be used to write a JavaScript function that will accept user input?
The prompt
method
The alert method
A form field
All of these
52. Which of these options is the most maintainable way to attach JavaScript functionality to an HTML element?
<p onclick=»alert(‘You clicked me!’)»> some text
</p>
<script> function fun(){alert(‘You clicked
me!’)} </script><a onclick=fun()>…</a>
<script>
function fun(){ alert(‘You clicked me!’); };
var el = document.getElementById(«click-target»);
el.onClick = fun;
</script>
<a id=»click-target»>…</a>
<a href=»javascript:alert(‘You clicked me!’)»>…</a>
53. 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>
The code will cause an error alert to be displayed if a numeric
character is entered, and the numeric character is removed.
The code will cause an error alert to be displayed if a non-numeric character is entered, and the
non-numeric character is removed.
The code will cause an error alert to be displayed if a numeric character is entered, and the
value of textbox is reset.
The code will cause an error alert to be displayed if a non-numeric character is entered, and the
value of textbox is reset.
54. What would be the default setting for the expires attribute of the document.cookie property?
The duration of the browser session
The duration the current document stays loaded
Twenty-four hours from the time the cookie is set
There is no default setting
The duration for which the machine is on
55. Which of the following choices will remove a selection option from the code below?
<button id”newbtn” onclick=”g();”>Remove</button>
<select name=”selectBox” id=”selectBox”>
<option value=”option1″>option1</option>
<option value=”option2″>option2</option>
<option value=”option3″>option3</option>
<option value=”option4″>option4</option>
</select>
<script>
function g(){
var index = 1;
var d = document.getElementById(“selectBox”);
var d_nested = d.childNodes[index];
var throwawayNode = d.deleteChild(d_nested);
}
</script>
<script>
function g(){
var index = 1;
var d = document.getElementById(“selectBox”);
var d_nested = d.childNodes[index];
var throwawayNode = d.clearChild(d_nested);
}
</script>
<script>
function g(){
var index = 1;
var d = document.getElementById(“selectBox”);
var d_nested = d.childNodes[index];
var throwawayNode = d.emptyChild(d_nested);
}
</script>
<script>
function g(){
var index = 1;
var d = document.getElementById(“selectBox”);
var d_nested = d.childNodes[index];
var throwawayNode = d.removeChild(d_nested);
}
</script>
56. Which of the following is incorrect regarding Strict mode in JavaScript?
It catches some common coding errors, throwing
exceptions.
It enables features that are confusing or poorly thought out.
It prevents, or throws errors, when relatively «unsafe» actions are taken (such as gaining access
to the global object).
57. Which of the following best describes a «for» loop?
«for» loop consists of six optional expressions, enclosed in
parentheses and separated by semicolons, followed by a statement executed in the loop.
«for» loop consists of five optional expressions, enclosed in parentheses and separated by
semicolons, followed by a statement executed in the loop.
«for» loop consists of four optional expressions, enclosed in parentheses and separated by
semicolons, followed by a statement executed in the loop.
«for» loop consists of three optional expressions, enclosed in parentheses and separated by
semicolons, followed by a statement executed in the loop.
58. Which of the following descriptions best describes the code below?
<script>
var variable1 = { fastFood: «spaghetti», length: 10 };
Object.freeze(variable1);
variable1.price = 50;
delete variable1.length;
</script>
Object is frozen, a property named «price» is added in the variable1
object, a property named «length» is deleted from this object. At the end of the code, the object
«variable1» contains 2 properties.
Object is frozen, a property named «price» is not added in the variable1 object, a property named
«length» is deleted from this object. At the end of the code, object «variable1» contains 1
properties.
Object is frozen, a property named «price» is added in the variable1 object, a property named
«length» is not deleted from this object. At the end of the code, object «variable1» contains 1
properties.
Object is frozen, a property named «price» is not added in the variable1 object, a property named
«length» is not deleted from this object. At the end of the code, object «variable1» contains 2
properties.
59. Which of the following is not a valid HTML event?
ondblclick
onmousemove
onclick
onblink
60. 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>
I
Is
s
I,s,
61. What is the final value of the variable bar in the following code?
var foo = 9;
bar = 5;
(function() {
var foo = 2;
bar= 1;
}())
bar = bar + foo;
10
14
3
7
62. Which of the following are JavaScript unit testing tools?
Buster.js, jQuery, YUI Yeti
QUnit, Modernizr, JsTestDriver
Node.js, Modernizr, Jasmine
Buster.js, YUI Yeti, Jasmine
63. Which of the following correctly uses a timer with a function named rearrange()?
tmr=setTimeout(«rearrange ()»,1)
tmr=Timer(1,»rearrange ()»)
tmr=Timer(«rearrange ()»,1)
tmr=setTimeout(1,»rearrange ()»)
64. Which of the following can be used to escape the ‘ character?
*
\
—
@
#
%
|
~
65. Which event can be used to validate the value in a field as soon as the user moves out of the field by pressing the tab key?
onblur
onfocus
lostfocus
gotfocus
None of these
66. Which of the following are not global methods and properties in E4X?
ignoreComments
ignoreWhiteSpace
setName()
setNamespace()
ignoreComments and ignoreWhiteSpace
setName() and setNamespace()
67. Which of the following will change the color of a paragraph’s text to blue when a user hovers over it, and reset it back to black when the user hovers out?
<p onmouseover=»style.color=’black'»
onmouseout=»style.color=’blue'»> The text of the paragraph..</p>
<p onmouseover=»style.color=’blue'» onmouseout=»style.color=’black'»> The text of the
paragraph..</p>
<p onmouseout=»style.color=’blue'»> The text of the paragraph..</p>
<p onmouseover=»style.color=’blue'»> The text of the paragraph..</p>
<p onmousein=»style.color=’blue'» onmouseout=»style.color=’black'»> The text of the
paragraph..</p>
68. What is the purpose of while(1) in the following JSON response?
while(1);[[‘u’,[[‘smsSentFlag’,’false’],[‘hideInvitations’,’false’],[‘remindOnRespondedEventsOnly’,’true’],[‘hideInvitations_remindOnRespondedEventsOnly’,’false_true’],[‘Calendar ID stripped for privacy’,’false’],[‘smsVerifiedFlag’,’true’]]]]
It’s invalid JSON code.
It makes it difficult for a third-party to insert the JSON response into an HTML document with a
<script> tag.
It iterates the JSON response.
It prevents the JSON response from getting executed.
69. Consider the three variables:
someText = ‘JavaScript1.2’;
pattern = /(\w+)(\d)\.(\d)/i;
outCome = pattern.exec(someText);
What does outCome[0] contain?
true
false
JavaScript1.2
null
0
70. The following are the samples for getting a selected value in the from a dropdown list:
<select id=»ddlViewBy»>
<option value=»1″>test1</option>
<option value=»2″ selected=»selected»>test2</option>
<option value=»3″>test3</option>
</select>
Which code block is correct?
var e = document.getElementById(«ddlViewBy»); var strUser =
e.options[e.selectedIndex].text;
var e = document.getElementById(«ddlViewBy»); var strUser =
e.options[e.selectedIndex].value;
var e = document.getElementByName(«ddlViewBy»); var strUser =
e.options[e.selectedIndex].text;
var e = document.getElementByName(«ddlViewBy»); var strUser =
e.options[e.selectedIndex].value;
71. var profits=2489.8237
Which of the following code(s) produces the following output?
output : 2489.824
profits.toFixed(4)
profits.toFixed(3)
profits.formatDollar(3)
profits.nuberFormat(3)
72. A form contains two fields named id1 and id2. How can you copy the value of the id2 field to id1?
document.forms[0].id1.value=document.forms[0].id2.value
document.forms[0].id2.value=document.forms[0].id1.value
document.id1.value=document.id2.value
document.id2.value=document.id1.value
73. How can the user’s previously navigated page be determined using JavaScript?
It is not possible in JavaScript. This can be done only through
server-side scripting.
Using the document.referrer property
Using the window object
None of these
74. Which of the following is not a valid method for looping an array?
var a= [1,2]; for (var i = 0; i < a.length; i++) { alert(a[i]);
}
var a= [1,2]; a.forEach( function(item) { alert(item); })
var a= [1,2]; a.map( function(item) { alert(item); })
var a= [1,2]; a.loop( function(item) { alert(item); })
75. Which of the following correctly sets a class for an element?
document.getElementById(elementId).className =
«Someclass»;
document.getElementById(elementId).setAttribute(«className», «Someclass»);
document.getElementById(elementId).class = «Someclass»;
document.getElementById(elementId).style = «Someclass»;
76. An HTML form contains 10 checkboxes all named «chkItems». Which JavaScript function can be used for checking all the checkboxes together?
function CheckAll() { for (z = 0; z <
document.forms.chkItems.length; z++) { document.forms.chkItems[z].checked=true } }
function CheckAll() { for (z = 0; z < document.forms[0].chkItems.length; z++) {
document.forms[0].chkItems[z].checked=true } }
function CheckAll() { for (z = 0; z < document.forms[0].chkItems.length; z++) {
document.forms[0].chkItems.list[z].checked=true } }
function CheckAll() { for (z = 0; z < document.forms[0].chkItems.length; z++) {
document.forms[0].chkItems.list[z].checked=false } }
77. What is the output of the following code?
var a = ‘A’.charCodeAt(0) + 5;
var b = ‘c’.charCodeAt(0) + 1;
var c = 0;
for (var i = 0; i < 10; i++) {
c = c + (a+b % 2);
}
alert(c);
700
60
0
760
78. Which of the following is/are true regarding JavaScript and multi-threading/concurrency?
JavaScript is single-threaded, forcing asynchronous events to a queue
to wait for execution.
JavaScript is multi-threaded, and behaves in a synchronous manner.
JavaScript can be single or multi-threaded, depending on the browser’s capabilities.
None of these.
79. Which of the following is not a valid Date Object method in JavaScript?
parse()
setDay()
setTime()
valueOf()
80. Consider the following JavaScript function to change the color of the text box named txtName:
function color(col) { document.forms[0].txtName.style.background=col }
Which of the following will change the color of the text box to green, as long as the user is pressing a key?
input type=»text» onkeydown=»color(‘white’)» onkeyup=»color(‘green’)»
name=»txtName»
input type=»text» onkeydown=»color(‘green’)» onkeyup=»color(‘white’)» name=»txtName»
input type=»text» onkeydown=»color(‘green’)» name=»txtName»
input type=»text» onkeydown=»color(‘white’)» name=»txtName»
input type=»text» onkeypress=»color(‘green’)» onkeyup=»color(‘white’)» name=»txtName»
81. What is the difference between call() and apply()?
The call() function accepts an argument list of a function, while the
apply() function accepts a single array of arguments.
The apply() function accepts an argument list of a function, while the call() function accepts a
single array of arguments.
The call() function accepts an object list of a function, while the apply() function accepts a
single array of an object.
The call() function accepts an object list of a function, while the apply() function accepts a
single array of an object.
82. Which of the following code snippets is more efficient, and why?
<script language=»JavaScript»>
for(i=0;i<document.images.length;i++)
document.images[i].src=»blank.gif»;
</script>
<script language=»JavaScript»>
var theimages = document.images;
for(i=0;i<theimages.length;i++)
theimages[i].src=»blank.gif»
</script>
Both are equally efficient.
The first code is more efficient as it contains less code.
The first code is more efficient as it employs object caching.
The second code is more efficient as it employs object caching.
83. What is the meaning of obfuscation in JavaScript?
Obfuscation is a keyword in JavaScript.
Making code unreadable using advanced algorithms.
Decrypting encrypted source code using advanced algorithms.
None of these.
84. Which of the following is not a valid JavaScript operator?
|
===
%=
^
85. Which of the following code snippets returns «[object object]»?
<script> var o = new Object(); o.toSource();
</script>
<script> var o = new Object(); o.valueOf(); </script>
<script> var o = new Object(); o.toString(); </script>
<script> var o = new Object(); o.getName(); </script>
86. Which of the following code snippets will correctly get the length of an object?
<script> var newObj = new Object(); newObj[«firstname»] =
«FirstName»; newObj[«lastname»] = «LastName»; newObj[«age»] = 21; Object.size = function(obj) { var size =
0, key; for (key in obj) { if (obj.hasOwnProperty(index)) size++; } return size; }; var size =
Object.size(newObj); </script>
<script> var newObj = new Object(); newObj[«firstname»] = «FirstName»; newObj[«lastname»] =
«LastName»; newObj[«age»] = 21; Object.size = function(obj) { var size = 0, key; for (key in obj) { if
(obj.hasOwnProperty(value)) size++; } return size; }; var size = Object.size(newObj);
</script>
<script> var newObj = new Object(); newObj[«firstname»] = «FirstName»; newObj[«lastname»] =
«LastName»; newObj[«age»] = 21; Object.size = function(obj) { var size = 0, key; for (key in obj) { if
(obj.hasOwnProperty(length)) size++; } return size; }; var size = Object.size(newObj);
</script>
<script> var newObj = new Object(); newObj[«firstname»] = «FirstName»; newObj[«lastname»] =
«LastName»; newObj[«age»] = 21; Object.size = function(obj) { var size = 0, key; for (key in obj) { if
(obj.hasOwnProperty(key)) size++; } return size; }; var size = Object.size(newObj);
</script>
87. 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 should the validate() function look like?
<script type=»text/javascript»> function Validate() {
if(document.forms[0].name.value == «») return true; else return false; } </script>
<script type=»text/javascript»> function Validate() { if(document.forms[0].name.value ==
«») return false; else return true; } </script>
script type=»text/javascript»> function Validate() { if(document.forms[0].name== «») return
false; else return true; } </script>
<script type=»text/javascript»> function Validate() { if(document.forms[0].name == «»)
return true; else return false; } </script>
88. Which of the following code snippets changes an image on the page?
var img = document.getElementById(«imageId»); img.src =
«newImage.gif»;
var img = document.getElementById(«imageId»); img.style.src = «newImage.gif»;
var img = document.getElementById(«imageId»); img.src.value = «newImage.gif»;
var img = document.getElementById(«imageId»); img = «newImage.gif»;
89. Which of the following results is returned by the JavaScript operator «typeof» for the keyword «null»?
function
object
string
number
90. What will be the final value of the variable «apt»?
var apt=2;
apt=apt<<2;
2
4
6
8
16
91. What would be the value of ‘ind’ after execution of the following code?
var msg=»Welcome to ExpertRating»
var ind= msg.substr(3, 3)
lco
com
ome
Welcome
92. Are the two statements below interchangeable?
object.property
object[»property»]
Yes
No
93. Which of the following code snippets will return all HTTP headers?
var req = new XMLHttpRequest(); req.open(‘GET’, document.location,
false); req.send(null); var headers = req.getAllResponseHeaders().toLowerCase();
alert(headers);
var req = new XMLHttpAccess(); req.open(‘GET’, document.location, false); req.send(null); var
headers = req.getAllResponseHeaders().toLowerCase(); alert(headers);
var req = new XMLHttpRequest(); req.open(‘GET’, document.location, false); req.send(null); var
headers = req.getResponseHeader().toLowerCase(); alert(headers);
var req = new XMLHttpRequestHeader(); req.open(‘GET’, document.location, false); req.send(null);
var headers = req.retrieveAllResponseHeaders().toLowerCase(); alert(headers);
94. Which of the following is the most secure and efficient way of declaring an array?
var a = []
var a = new Array()
var a = new Array(n)
var a
95. Select the following function that shuffles an array?
function shuffle(array) { var tmp, current, top = array.length;
if(top) while(—top) { current = Math.floor(Math.random() * (top + 1)); tmp = array[current]; array[current]
= array[top]; array[top] = tmp; } return array; }
function shuffle(array) { return array.sort(function(a,b) { return (a-b); }); }
function shuffle(array) { var results = new Array(); var sorted_arr = array.sort(); for (var i =
0; i < array.length — 1; i++) { if (sorted_arr[i + 1] == sorted_arr[i]) {
results.push(sorted_arr[i]); } } return results; }
function shuffle(array) { for (var tmp, cur, top=array.length; top—;){ cur = (Math.random() *
(top + 1)) << 0; tmp = array[cur]; array[cur] = array[top]; array[top] = tmp; } return
array.sort(); }
96. Which of the following code snippets removes objects from an associative array?
delete array[«propertyName»];
array.propertyName.remove();
array.splice(index, 1);
array[«propertyName»].remove();
97. What is the error in the statement: var charConvert = toCharCode(‘x’);?
toCharCode() is a non-existent method.
Nothing. The code will work fine.
toCharCode only accepts numbers.
toCharCode takes no arguments.
98. What value would JavaScript assign to an uninitialized variable?
NaN
null
undefined
false
99. Which of the following Regular Expression pattern flags is not valid?
gi
p
i
g
100. Which of the following built-in functions is used to access form elements using their IDs?
getItem(id)
getFormElement(id)
getElementById(id)
All of these
101. Which of the following statements is correct?
There is no undefined property in JavaScript.
Undefined object properties can be checked using the following code: if (typeof something ==
null) alert(«something is undefined»);
It is not possible to check for undefined object properties in JavaScript.
Undefined object properties can be checked using the following code: if (typeof something ===
«undefined») alert(«something is undefined»);
102. Which of the following choices will turn a string into a JavaScript function call (case with objects) of the following code snippet?
<script>
window.foo = {
bar: {
baz: function() {
alert(‘Hello!’);
}
}
};
</script>
bar[‘baz’]();
object[‘foo’][‘bar’][‘baz’]();
document[‘foo’][‘bar’][‘baz’]();
window[‘foo’][‘bar’][‘baz’]();
103. Which of the following options can be used for adding direct support for XML to JavaScript?
E4X
egex
Generators and Iterators
let
104. Which of the following will detect which DOM element has the focus?
document.activeElement
document.ready
document.referrer
document.getelementbyid
105. Which of the following will randomly choose an element from an array named myStuff, given that the number of elements changes dynamically?
randomElement = myStuff[Math.floor(Math.random() *
myStuff.length)];
randomElement = myStuff[Math.ceil(Math.random() * myStuff.length)];
randomElement = myStuff[Math.random(myStuff.length)];
randomElement = Math.random(myStuff.length);
106. How can global variables be declared in JavaScript?
All variables are local in JavaScript.
Declare the variable between the ‘script’ tags, and outside a function to make the variable
global
Precede the variable name with the constant global
Declare the variable in an external file
107. Which of the following methods will copy data to the Clipboard?
execClipboard(‘Copy’)
copyCommand(‘Clipboard’)
execCommand(‘Copy’)
execClipboard(‘Copy’)
108. Which of the following code snippets trims whitespace from the beginning and end of the given string str?
str.replace(/^\s+|\s+$/g, »);
str.replace(/^\s+/,»);
str.replace(/\s+$/,»);
str.replace(/\s+/g,’ ‘);
109. Which of the following can be used to invoke an iframe from a parent page?
window.frames
document.getElementById
document.getelementsbyname
document.getelementsbyclassname
110. What does the following JavaScript code do?
contains(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}
It calculates an array’s length.
It compares ‘a’ and ‘obj’ in an array.
The code will cause an error.
It checks if an array contains ‘obj’.
111. If an image is placed styled with z-index=-1 and a text paragraph is overlapped with it, which one will be displayed on top?
The paragraph.
The image.
It depends on other rules.
112. Which of the following code snippets gets an image’s dimensions (height & width) correctly?
var img = document.getElementById(‘imageid’); var width =
img.clientWidth; var height = img.clientHeight;
var img = document.getElementById(‘imageid’); var width = img.width; var height =
img.height;
var img = document.getElementById(‘imageid’); var width = img.getAttribute(‘width’); var height =
img.getAttribute(‘height’);
var img=document.getElementById(«imageid»); var width=img.offsetWidth; var
height=img.offsetHeight;
113. Which of the following statements are true regarding the code below?
<script>
alert(«foo» === new String(«foo»)); // output false
</script>
The «===» operator always returns false.
The «===» operator returns true only if they refer to the same object (comparing by reference)
and if both the primitive and the object have the same value.
The «===» operator returns true only if the object (comparing by reference) and the primitive
have the same value.
The «===» operator does not work for objects.
114. Which of the following statements are true regarding the «this» keyword in JavaScript?
The value of «this» can be set by assignment during execution, and it
will be the same each time the function is called.
Inside a function, the value of «this» depends on how many times the function is
called.
Inside a function, the value of «this» depends on how the function is called (as a simple call,
an object method, a constructor, etc.).
In strict mode, the value of «this» may change from whatever it is set to, when entering the
execution context.
115. Which of the following is not a correct way to empty the array a?
a = new Array();
a = [];
a.splice(0,a.length);
a.clear()
116. Which of the following is the correct way to resize an iframe based on content?
function resizeIframe(height)
{document.getElementById(‘frame_name_here’).height = parseInt(height)+60;}
<iframe id=’frame_name_here’ src=’src.htm’></iframe>
function resizeIframe(height)
{document.getElementByName(‘frame_name_here’).height = parseInt(height)+60;}
<iframe id=’frame_name_here’ src=’src.htm’></iframe>
function resizeIframe(height)
{document.getElementByDivId(‘frame_name_here’).height = parseInt(height)+60;}
<iframe id=’frame_name_here’ src=’src.htm’></iframe>
None of these
117. Consider the three variables:
someText = ‘JavaScript1.2’;
pattern = /(\w+)(\d)\.(\d)/i;
outCome = pattern.exec(someText);
What does pattern.ignoreCase contain?
true
false
undefined
null
0
118. Which of the following is not a valid JavaScript function?
apply()
call()
toString()
All the other options are valid.
119. What does the following code snippet do?
<input type=»radio» name=»r1″ value=»radio1″ onclick=»this.checked=false;alert(‘sorry’)»>
The code is invalid.
The code makes it necessary for the user to select the radio button.
The code disables the radio button.
The code displays an alert when the user selects the button.
120. How can properties be added to an object class?
With the prototype() method
With the prototype property
It cannot be done.
With the «this» object
121. Which of the following will correctly check if an object is an array?
Note: There may be more than one right answer.
Object.prototype.toString.call(arr) === ‘[object Array]’
Array.isArray(arr)
Object.isArray(arr)
None of these
122. Which of the following check if an object has a specific property?
hasOwnProperty()
hasProperty()
It is browser-dependent.
None of these.
123. Given the following window.open function:
window.open(url,name,»attributes»)
How can it be ensured that different URLs are opened in the same window?
The second attribute, name, should be the same.
The name attribute should be null.
The name attribute should be omitted.
The name attribute should be different.
None of these.
124. Which of the following code snippets renders a button invisible?
var button = document.getElementById(‘buttonId’);
button.style.display=’none’
var button = document.getElementById(‘buttonId’);
button.style.display=’block’
var button = document.getElementById(‘btn’);
button.style.visibility=’false’;
var button = document.getElementById(‘btn’);
button.style.visibility=’disabled’;
125. Why does (0 < 5 < 3) return true?
Order of operations produces (true < 3), which returns
true.
Order of precedence produces (true < 3), which returns true.
Order of operations produces (false < 3), which returns true.
None of these
126. What is the cleanest, most effective way to validate decimal numbers in JavaScript?
IsNumeric()
isNaN()
valid()
isDecimal()
127. Consider three variables:
someText = ‘JavaScript1.2’;
pattern = /(\w+)(\d)\.(\d)/i;
outCome = pattern.exec(someText);
What does pattern.global contain?
true
false
undefined
null
1
128. Which of the following is the best reason for not using «for…in» with array iteration?
for..in should be used to iterate over an array where index order is
important.
for..in should not be used to iterate over an array where index order is important.
for…in loops iterate over non–enumerable properties.
for…in loops do not iterate over enumerable properties.
129. What does the + sign in front of a function name mean in JavaScript?
It forces the parser to treat the + sign as a part of an
expression.
The + sign is used as a cast operator.
It is used to denote a type of object in JavaScript.
None of these.
130. Which of the following will implement a singleton pattern in JavaScript?
<script>
var anObject = {
method1: function () {
// …
},
method2: function () {
// …
}
};
</script>
<script>
function method1(){
// …
}
function method2(){
// …
}
</script>
<script>
var method1 = function(){
// …
}
var method2 = function(){
// …
}
</script>
<script>
var method1;
var method2;
</script>
131. Which of the following code snippets will correctly detect a touchscreen device?
function isTouchDevice() {
return !!(‘ontouchstart’ in window) || !!(‘onmsgesturechange’ in window);
};
function isTouchDevice() {
try {
document.body.createEvent(«TouchEvent»);
return true;
} catch (e) {
return false;
}
}
function isTouchDevice(){
return (typeof(navigator.ontouchstart) != ‘undefined’) ? true : false;
}
function isTouchDevice(){
return (navigator.msMaxTouchPoints == 0);
}
132. Which of the following shows examples of valid auto increment/decrement loops?
for(var i=0; i < 100; i++){}
for(var i=0; i > -100; i—){}
for(var i=0; i < 100; i+){}
for(var i=0; i > -100; i-){}
for(var i=0; i > 100; i++){}
for(var i=0; i < -100; i—){}
for(var i=0; i > 100; i+){}
for(var i=0; i < -100; i-){}
133. 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>
1
ain
7,29
7
ain,ain
134. The following are sample codes on how to merge properties of two JavaScript objects dynamically:
var obj1 = { food: ‘pizza’, car: ‘ford’ }
var obj2 = { animal: ‘dog’ }
Which of the following are JavaScript codes?
Note: There may be more than one right answer.
obj1.merge(obj2);
function MergeRecursive(obj1,obj2){
var obj3 = {};
for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
return obj3;
}
function MergeRecursive(obj1, obj2) {
for (var p in obj2) {
try {
// Property in destination object set; update its value.
if ( obj2[p].constructor==Object ) {
obj1[p] = MergeRecursive(obj1[p], obj2[p]);
} else {
obj1[p] = obj2[p];
}
} catch(e) {
// Property in destination object not set; create it and set its value.
obj1[p] = obj2[p];
}
}
return obj1;
}
Object.extend = function(destination,source) {
for (var property in source)
destination[property] = source[property];
return destination;
}
obj1.extend(obj2)
135. You need to be able to determine which page of the web site has been the most recently modified. Which object would enable you to do this?
a. document
b. window
c. history
d. browser
e. form
f. location
136. Which of the following are the valid JavaScript codes to obtain the number of milliseconds since the epoch?
Note: There may be more than one right answer.
var timestamp = new Date().getTime();
var timestamp = Number(new Date());
var timestamp = Date.now;
var timestamp = new Date().valueOf();
137. Which of the following ‘if’ statements is correctly used to get the size of both ‘variable1’ and ‘variable2’ objects?
var variable1 = {‘name’:’theName’, ‘address’:’theAddress’,’age’: ’18’}
var variable2 = [‘theName’,’theAddress’,’18’];
variable1[«name»] = «theName2»;
variable1[«name»] = «theName3»;
variable1[«name2»] = «theName4»;
variable1[«name2»] = «theName5»;
Object.size = function(importer) {
var exporter = 0, key;
for (key in importer) {
if (importer.hasOwnProperty(key)) exporter++;
}
return exporter;
};
if(typeof(variable1)==’object’ &&
typeof(variable2)==’array’){
Object.size(variable1);
variable2.length;
}
if(typeof(variable1)==’array’ && typeof(variable2)==’object’){
Object.size(variable1);
variable2.length;
}
if(typeof(variable1) > typeof(variable2)){
Object.size(variable1);
variable2.length;
}
if(typeof(variable1) == typeof(variable2)){
Object.size(variable1);
variable2.length;
}
138. Consider the following JavaScript arrays:
var a = [1, 2];
var b = [3, 4, 5];
Which of the following will append the contents of array «b» to array «a»?
a.push(b);
a.splice(0,0,b);
a = b.concat(a);
a.join(b);
139. How can it be determined if JavaScript is disabled in the user’s browser?
It is browser-dependent.
There is no way to detect if JavaScript is disabled.
Use the HTML <noscript> tag to display different content if JavaScript is
disabled.
None of these.
140. Which of the following choices shows the correct result for the code below? var arr = []; arr[0] = «Jani»; arr[1] = «Hege»; arr[2] = «Stale»; arr[3] = «Kai Jim»; arr[4] = «Borge»; console.log(arr.join()); arr.splice(2, 0, «Lene»); console.log(arr.join());
Jani,Hege,Stale,Kai Jim,Borge
Lene,Jani,Hege,Stale,Kai Jim,Borge
Jani,Hege,Stale,Kai Jim,Borge
Jani,Hege,Lene,Stale,Kai Jim,Borge
Jani,Hege,Stale,Kai Jim,Borge
Jani,Hege,Stale,Kai Jim,Lene,Borge
Jani,Hege,Stale,Kai Jim,Borge
Jani,Hege,Stale,Kai Jim,Borge
141. Consider the following scenario:
The document.write() method is embedded to write some text within a pair of <td></td> table tags. Upon loading the file, however, garbled text appears on the section of the page where the text should be. What could be the reason for this?
The browser does not support JavaScript.
An older version of the browser is being used.
The browser does not support cookies.
142. What is the output of the following code?
var a = 5;
var b = 1;
if(!!»false») {
a = a + 5;
b = 3;
};
if(!!0) {
a = a + 5;
b = b + 2;
};
alert(a+b);
13
20
6
None of these
143. Consider the following code:
var vNew=new Date()
Which of the following options will return true?
vNew instanceof boolean
vNew instanceof object
vNew instanceof Date
All of these
144. Which of the following will detect if the browser supports a certain CSS property?
typeof document.body.style.borderRadius == ‘string’
typeof document.body.style.borderRadius == ‘undefined’
typeof document.body.style.borderRadius == true
It is impossible.
145. Which of the following is not a valid JavaScript operator?
*=
/=
%=
^+
146. Which of the following is not a valid code for redirect to stackoverflow.com?
Note: There may be more than one right answer.
window.location.href = «http://stackoverflow.com»;
window.location.href («http://stackoverflow.com»);
window.location.replace=»http://stackoverflow.com»;
window.location.replace(«http://stackoverflow.com»);
147. The following statements show two ways of calling a JavaScript function:
i)onclick = «a();»
ii)onclick=»JavaScript:a();»
Which of the following options is correct, with regard to the two statements above?
There is no difference between the two statements.
The first statement is incorrect and the second one is correct.
The first statement is correct and the second statement is incorrect.
148. Which of the following code snippets will trigger an input type=»file» attribute when an element with a «newbtn» ID is clicked?
<button id»newbtn» onclick=»grt();»>Upload</button>
<form>
<input id=»thisId» type=»file» name=»upload» />
</form>
</form>
function
grt(){document.getElementById(‘thisId’).keypress();}
function grt(){document.getElementById(‘thisId’).load();}
function grt(){document.getElementById(‘thisId’).dblclick();}
function grt(){document.getElementById(‘thisId’).click();}