1. 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?
Answers:
Answers:
Answers:
Answers:
var object0 = {};
Object.defineProperty(object0, “prop0”, { value : 1, enumerable:false, configurable : true });
Object.defineProperty(object0, “prop1”, { value : 2, enumerable:true, configurable : false });
Object.defineProperty(object0, “prop2”, { value : 3 });
object0.prop3 = 4;
Answers:
Answers:
var a=”adam”
var b=”eve”
Which of the following would return the sentence “adam and eve”?
Answers:
Answers:
Answers:
Answers:
<script>
var variable1 = { fastFood: “spaghetti”, length: 10 };
Object.freeze(variable1);
variable1.price = 50;
delete variable1.length;
</script>
Answers:
Answers:
<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
Answers:
<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?
Answers:
var foo = 9;
bar = 5;
(function() {
var foo = 2;
bar= 1;
}())
bar = bar + foo;
Answers:
Answers:
Answers:
<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?
Answers:
<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?
Answers:
Answers:
<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?
Answers:
Answers:
Answers:
var apt=2;
apt=apt<<2;
Answers:
Answers:
Answers:
Answers:
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?
Answers:
Answers:
<script type=”text/JavaScript”>
function ValidateField()
{
if(document.forms[0].txtId.value ==””)
{return false;}
return true;
}
</script>
Which of the following options will call the function as soon as the user leaves the field?
Answers:
Answers:
<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?
Answers:
Answers:
function validate(field) {
var valid=”ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”;
var ok=”yes”;
var temp;
for(var i=0;i<field.value.length;i++) {
temp=”” + field.value.substring(i,i+1)
if(valid.indexOf(temp)==”-1”) {
ok=”no”;
}
}
if(ok==”no”) {
alert(”error”);
field.focus();
}
}
Answers:
<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?
Answers:
<script>
var variableName= function(){};
</script>
Answers:
Answers:
Answers:
var msg=”Welcome to ExpertRating”
var ind= msg.substr(3, 3)
Answers:
object.property
object[”property”]
Answers:
Answers:
Answers:
<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?
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
while(1);[[‘u’,[[‘smsSentFlag’,’false’],[‘hideInvitations’,’false’],[‘remindOnRespondedEventsOnly’,’true’],[‘hideInvitations_remindOnRespondedEventsOnly’,’false_true’],[‘Calendar ID stripped for privacy’,’false’],[‘smsVerifiedFlag’,’true’]]]]
Answers:
someText = ‘JavaScript1.2’;
pattern = /(w+)(d).(d)/i;
outCome = pattern.exec(someText);
What does outCome[0] contain?
Answers:
<script>
window.foo = {
bar: {
baz: function() {
alert(‘Hello!’);
}
}
};
</script>
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
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());
Answers:
Answers:
Answers:
Answers:
<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>
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
contains(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}
Answers:
Answers:
Answers:
<script>
variableA = [6,8];
variableB =[7,9];
variableC = variableA + variableB;
</script>
Answers:
<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?
Answers:
Which of the following code(s) produces the following output?
output : 2489.824
Answers:
Answers:
<button id=”toggle”>Toggle</button>
<div id=”terd”>Change Background Color.</div>
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
- reduce()
- reduceRight()
- everse()
- pop()
Answers:
- 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.
Answers:
- It is not possible using JavaScript.
- Using the navigator object
- Using the window object
- Using the document object
- None of these.
Answers:
- var b = ‘a’; var result = b.toUpperCase() + ‘b’ + ‘b’.toUpperCase() +’C'[‘toLowerCase’](); alert(result);
- var b = ‘a’; var result = b.toUpperCase() + ‘b’ + ‘b’.toUpperCase() +’c'[‘toUpperCase’](); alert(result);
- var b = ‘a’; var result = b.toUpperCase() + b + ‘b’.toUpperCase() +’C'[‘toLowerCase’](); alert(result);
- var b = ‘a’; var result = b.toUpperCase() + ‘b’ + ‘b’.toUpperCase() +C; alert(result);
var object0 = {};
Object.defineProperty(object0, “prop0”, { value : 1, enumerable:false, configurable : true });
Object.defineProperty(object0, “prop1”, { value : 2, enumerable:true, configurable : false });
Object.defineProperty(object0, “prop2”, { value : 3 });
object0.prop3 = 4;
Answers:
- Object ‘object0’ contains 4 properties. Property ‘prop2’ and property ‘prop3’ are available in the for…in loop. Property ‘prop0’ and property ‘prop1’ are available to delete.
- Object ‘object0’ contains 4 properties. Property ‘prop1’ and property ‘prop2’ are available in the for…in loop. Property ‘prop2’ and property ‘prop3’ are available to delete.
- Object ‘object0’ contains 4 properties. Property ‘prop0’ and property ‘prop2’ are available in the for…in loop. Property ‘prop0’ and property ‘prop2’ are available to delete.
- Object ‘object0’ contains 4 properties. Property ‘prop1’ and property ‘prop3’ are available in the for…in loop. Property ‘prop0’ and property ‘prop3’ are available to delete.
Answers:
- String.prototype.repeat = function( num ) { return new Array( num + 1 ).join( this ); }
- function repeat(pattern, count) { if (count < 1) return ”; var result = ”; while (count > 0) { if (count & 1) result += pattern; count >>= 1, pattern += pattern; } return result; }
- String.prototype.repeat = function(count) { if (count < 1) return ”; var result = ”, pattern = this.valueOf(); while (count > 0) { if (count & 1) result += pattern; count >>= 1, pattern += pattern; } return result; };
- String.prototype.repeat = function (n, d) { return –n ? this + (d || ”) + this.repeat(n, d) : ” + this };
var a=”adam”
var b=”eve”
Which of the following would return the sentence “adam and eve”?
Answers:
- a.concatinate(“and”, b)
- a.concat(“and”, b)
- a.concatinate(” and “, b)
- a.concat(” and “, b)
Answers:
- <script> var str = ‘something — something_else’; var substrn = str.split(‘ — ‘); </script>
- <script> var str = ‘something — something_else’; var substrn = split.str(‘ — ‘); </script>
- <script> var str = ‘something — something_else’; var substrn = str.split(‘ – ‘,’ – ‘); </script>
- <script> var str = ‘something — something_else’; var substrn = split.str(‘ – ‘,’ – ‘); </script>
Answers:
- document
- window
- history
- browser
- form
- location
Answers:
- “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.
<script>
var variable1 = { fastFood: “spaghetti”, length: 10 };
Object.freeze(variable1);
variable1.price = 50;
delete variable1.length;
</script>
Answers:
- 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.
Answers:
- ondblclick
- onmousemove
- onclick
- onblink
<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
Answers:
- I
- Is
- s
- I,s,
<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?
Answers:
- logo.source=”companylogo2.gif”
- logo.source=”companylogo1.gif”
- document.getElementById(‘logo’).src=”companylogo1.gif”
- document.getElementById(‘logo’).src=”companylogo2.gif”
var foo = 9;
bar = 5;
(function() {
var foo = 2;
bar= 1;
}())
bar = bar + foo;
Answers:
- 10
- 14
- 3
- 7
Answers:
- Buster.js, jQuery, YUI Yeti
- QUnit, Modernizr, JsTestDriver
- Node.js, Modernizr, Jasmine
- Buster.js, YUI Yeti, Jasmine
Answers:
- event.button == 2
- event.button == 4
- event.click == 2
- event.click == 4
<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?
Answers:
- 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”
<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?
Answers:
- body onload=”message()”
- body onunload=”message()”
- body onsubmit=”message()”
- body onreset=”message()”
Answers:
- <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>
<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?
Answers:
- <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>
Answers:
- 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”;
Answers:
- function
- object
- string
- number
var apt=2;
apt=apt<<2;
Answers:
- 2
- 4
- 6
- 8
- 16
Answers:
- console.log(obj)
- console.print(obj)
- console.echo(obj);
- None of these
Answers:
- RegExpObject.exec()
- RegExpObject.exec(string)
- RegExpObject.exec(parameter1,parameter2)
- None of these
Answers:
- arr.push(“New Item”)
- arr[arr.length] = “New Item”
- arr.unshift(“New Item”)
- arr.append(“New Item”)
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?
Answers:
- 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()”
Answers:
- 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”; }
<script type=”text/JavaScript”>
function ValidateField()
{
if(document.forms[0].txtId.value ==””)
{return false;}
return true;
}
</script>
Which of the following options will call the function as soon as the user leaves the field?
Answers:
- 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()”
Answers:
- i
- m
- g
- s
<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?
Answers:
- logo.source=”companylogo2.gif”
- logo.source=”companylogo1.gif”
- document.getElementById(‘logo’).src=”companylogo1.gif”
- document.getElementById(‘logo’).src=”companylogo2.gif”
Answers:
- if (typeof vRast=”undefined”) {}
- if (typeof vRast ==”undefined”) {}
- if (vRast.defined =true) {}
- if (vRast.defined ==true) {}
function validate(field) {
var valid=”ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”;
var ok=”yes”;
var temp;
for(var i=0;i<field.value.length;i++) {
temp=”” + field.value.substring(i,i+1)
if(valid.indexOf(temp)==”-1”) {
ok=”no”;
}
}
if(ok==”no”) {
alert(”error”);
field.focus();
}
}
Answers:
- It will force a user to enter only numeric values.
- It will force a user to enter only alphanumeric values.
- It will force a user to enter only English alphabet character values.
- None of these.
<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?
Answers:
- 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”
<script>
var variableName= function(){};
</script>
Answers:
- return variableName;
- nameof variableName;
- isFunction variableName;
- typeof variableName;
Answers:
- img id=”imageID” src=”image1.gif” width=”50″ height=”60″ onmousedown=”changeimg(image1.gif)” onmouseup=”changeimg(image2.gif)”
- img id=”imageID” src=”image1.gif” width=”50″ height=”60″ onmouseclick=”changeimg(image2.gif)” onmouseup=”changeimg(image1.gif)”
- img id=”imageID” src=”image2.gif” width=”50″ height=”60″ onmousedown=”changeimg(image1.gif)” onmouseup=”changeimg(image2.gif)”
- img id=”imageID” src=”image2.gif” width=”50″ height=”60″ onmousedown=”changeimg(image2.gif)” onmouseup=”changeimg(image1.gif)”
- img id=”imageID” src=”image1.gif” width=”50″ height=”60″ onmousedown=”changeimg(‘image2.gif’)” onmouseup=”changeimg(‘image1.gif’)”
Answers:
- 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
var msg=”Welcome to ExpertRating”
var ind= msg.substr(3, 3)
Answers:
- lco
- com
- ome
- Welcome
object.property
object[”property”]
Answers:
- Yes
- No
Answers:
- send()
- throw()
- next()
- stop()
Answers:
- 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);
<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?
Answers:
- body onload=”message()”
- body onunload=”message()”
- body onsubmit=”message()”
- body onreset=”message()”
Answers:
- var a = []
- var a = new Array()
- var a = new Array(n)
- var a
Answers:
- gi
- p
- i
- g
Answers:
- getItem(id)
- getFormElement(id)
- getElementById(id)
- All of these
Answers:
- 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”);
Answers:
- tmr=setTimeout(“rearrange ()”,1)
- tmr=Timer(1,”rearrange ()”)
- tmr=Timer(“rearrange ()”,1)
- tmr=setTimeout(1,”rearrange ()”)
Answers:
- *
- –
- @
- #
- %
- |
- ~
Answers:
- onblur
- onfocus
- lostfocus
- gotfocus
- None of these
Answers:
- 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.
Answers:
- ignoreComments
- ignoreWhiteSpace
- setName()
- setNamespace()
- ignoreComments and ignoreWhiteSpace
- setName() and setNamespace()
Answers:
- <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>
while(1);[[‘u’,[[‘smsSentFlag’,’false’],[‘hideInvitations’,’false’],[‘remindOnRespondedEventsOnly’,’true’],[‘hideInvitations_remindOnRespondedEventsOnly’,’false_true’],[‘Calendar ID stripped for privacy’,’false’],[‘smsVerifiedFlag’,’true’]]]]
Answers:
- 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.
someText = ‘JavaScript1.2’;
pattern = /(w+)(d).(d)/i;
outCome = pattern.exec(someText);
What does outCome[0] contain?
Answers:
- true
- false
- JavaScript1.2
- null
- 0
<script>
window.foo = {
bar: {
baz: function() {
alert(‘Hello!’);
}
}
};
</script>
Answers:
- bar[‘baz’]();
- object[‘foo’][‘bar’][‘baz’]();
- document[‘foo’][‘bar’][‘baz’]();
- window[‘foo’][‘bar’][‘baz’]();
Answers:
- (navigator.Cookie)? true : false
- (application.cookieEnabled)? true : false
- (navigator.cookieEnabled)? true : false
- (application.cookie)? true : false
Answers:
- E4X
- egex
- Generators and Iterators
- let
Answers:
- document.activeElement
- document.ready
- document.referrer
- document.getelementbyid
Answers:
- 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);
Answers:
- 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
Answers:
- Location
- Window
- Screen
- Navigator
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());
Answers:
- firststep1second
- step1step2
- step1
- step1step2step3
Answers:
- execClipboard(‘Copy’)
- copyCommand(‘Clipboard’)
- execCommand(‘Copy’)
- execClipboard(‘Copy’)
Answers:
- str.replace(/^s+|s+$/g, ”);
- str.replace(/^s+/,”);
- str.replace(/s+$/,”);
- str.replace(/s+/g,’ ‘);
Answers:
- 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.
<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>
Answers:
- 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.
Answers:
- Obfuscation is a keyword in JavaScript.
- Making code unreadable using advanced algorithms.
- Decrypting encrypted source code using advanced algorithms.
- None of these.
Answers:
- ?
- *
- +
- #
Answers:
- |
- ===
- %=
- ^
Answers:
- <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>
Answers:
- window.frames
- document.getElementById
- document.getelementsbyname
- document.getelementsbyclassname
Answers:
- 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(); }
Answers:
- delete array[“propertyName”];
- array.propertyName.remove();
- array.splice(index, 1);
- array[“propertyName”].remove();
Answers:
- toCharCode() is a non-existent method.
- Nothing. The code will work fine.
- toCharCode only accepts numbers.
- toCharCode takes no arguments.
Answers:
- NaN
- null
- undefined
- false
contains(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}
Answers:
- 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’.
Answers:
- The paragraph.
- The image.
- It depends on other rules.
Answers:
- 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;
<script>
variableA = [6,8];
variableB =[7,9];
variableC = variableA + variableB;
</script>
Answers:
- 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.
<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?
Answers:
- 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;
Which of the following code(s) produces the following output?
output : 2489.824
Answers:
- profits.toFixed(4)
- profits.toFixed(3)
- profits.formatDollar(3)
- profits.nuberFormat(3)
Answers:
- 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
<button id=”toggle”>Toggle</button>
<div id=”terd”>Change Background Color.</div>
Answers:
- <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>
Answers:
- 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
Answers:
- 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); })
Answers:
- document.getElementById(elementId).className = “Someclass”;
- document.getElementById(elementId).setAttribute(“className”, “Someclass”);
- document.getElementById(elementId).class = “Someclass”;
- document.getElementById(elementId).style = “Someclass”;
Answers:
- 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 } }
No comments:
Post a Comment