Upwork Test Answers: Get all the correct answers of most recent and possible Upwork Tests A to Z (Updated on Jan, 2016)
Cover Letter Templates: These cover letter samples are not only for Upwork job, but also you will have some idea about your real life job
 
Freelance Profile Overviews: Different Profile samples and overviews of experts, advanced and intermediate level freelancers
For Newbie of Upwork: Upwork Help - How to apply for a job in Upwork with 10 most important articles about Upwork

A to Z View - All Upwork Test Answers

Upwork Web Development: Javascript Test Answer

In this post you'll have all the Upwork Javascript Test answers of Upwork Web Development category with more than 80 questions and answers recently updated.

Please press Ctrl + F to find your required answer of the test and if you browse all the below mentioned 3 parts you will have all the answers of the Javascript Test Answers.

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: • reduceRight()

 2. Which of the following is true about setTimeOut()?
 Answers: • The statement(s) it executes run(s) only once.

 3. How can the operating system of the client machine be detected?
 Answers: • Using the navigator object

 4. Which of the following prints "AbBc"?
 Answers: • var b = 'a'; var result = b.toUpperCase() + 'b' + 'b'.toUpperCase() +'C'['toLowerCase'](); alert(result);

 5. Which of the following descriptions is true for the code below?

 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 'prop1' and property 'prop3' are available in the for...in loop. Property 'prop0' and property 'prop3' are available to delete.


 6. Performance-wise, which is the fastest way of repeating a string in JavaScript?
 Answers: • 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; };

 7. Consider the following variable declarations:

 var a="adam"
 var b="eve"

 Which of the following would return the sentence "adam and eve"?
 Answers: • a.concat(" and ", b)

 8. Which of the following code snippets will correctly split "str"?
 Answers: • <script> var str = 'something -- something_else'; var substrn = str.split(' -- '); </script>

 9. Which object can be used to ascertain the protocol of the current URL?
 Answers: • location

 10. Which of the following best describes a "for" loop?
 Answers: • "for" loop consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement executed in the loop.

 11. 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>
 Answers: • 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.

 12. Which of the following is not a valid HTML event?
 Answers: • onblink

 13. 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
 Answers: • s

 14. 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?
 Answers: • document.getElementById('logo').src="companylogo2.gif"

 15. 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;
 Answers: • 10

 16. Which of the following are JavaScript unit testing tools?
 Answers: • Buster.js, YUI Yeti, Jasmine

 17. Which of the following can be used for disabling the right click event in Internet Explorer?
 Answers: • event.button == 2

 18. 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?
 Answers: • document.getElementById('ERImage').src="Image2.jpg"

 19. 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?
 Answers: • body onload="message()"

 20. Which of the following code snippets will correctly get the length of an object?
 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(key)) size++; } return size; }; var size = Object.size(newObj); </script>

 21. 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?
 Answers: • <script type="text/javascript"> function Validate() { if(document.forms[0].name.value == "") return false; else return true; } </script>

 22. Which of the following code snippets changes an image on the page?
 Answers: • var img = document.getElementById("imageId"); img.src = "newImage.gif";

 23. Which of the following results is returned by the JavaScript operator "typeof" for the keyword "null"?
 Answers: • object

 24. What will be the final value of the variable "apt"?

 var apt=2;
 apt=apt<<2;
 Answers: • 8

 25. How can a JavaScript object be printed?
 Answers: • console.log(obj)

 26. Which of the following is the correct syntax for using the JavaScript exec() object method?
 Answers: • RegExpObject.exec(string)

 27. Having an array object var arr = new Array(), what is the best way to add a new item to the end of an array?
 Answers: • arr.push("New Item")

 28. 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?
 Answers: • input name=txtId type="text" onblur="return ValidateField()"

 29. Which of following uses the "with" statement in JavaScript correctly?
 Answers: • with (document.getElementById("blah").style) { background = "black"; color = "blue"; border = "1px solid green"; }

 30. Consider the following JavaScript validation function:

 <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" onblur="return ValidateField()"

 31. Which of the following modifiers must be set if the JavaScript lastIndex object property was used during pattern matching?
 Answers: • g

 32. 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?
 Answers: • document.getElementById('logo').src="companylogo2.gif"

 33. Which of the following will check whether the variable vRast exists or not?
 Answers: • if (typeof vRast =="undefined") {}

 34. What would be the use of the following code?

 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 English alphabet character values.

 35. 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?
 Answers: • document.getElementById('ERImage').src="Image2.jpg"

 36. Which of the following choices will detect if "variableName" declares a function?

 <script>
 var variableName= function(){};
 </script>
 Answers: • typeof variableName;

 37. Which of the following choices will change the source of the image to "image2.gif" when a user clicks on the image?
 Answers: • img id="imageID" src="image1.gif" width="50" height="60" onmousedown="changeimg(image1.gif)" onmouseup="changeimg(image2.gif)"

 38. How can created cookies be deleted using JavaScript?
 Answers: • Overwrite with an expiry date in the past

 39. What would be the value of 'ind' after execution of the following code?

 var msg="Welcome to ExpertRating"
 var ind= msg.substr(3, 3)
 Answers: • com

 40. Are the two statements below interchangeable?

 object.property
 object[''property'']
 Answers: • Yes

 41. Which of the following is not a valid method in generator-iterator objects in JavaScript?
 Answers: • stop()

 42. Which of the following code snippets will return all HTTP headers?
 Answers: • var req = new XMLHttpRequest(); req.open('GET', document.location, false); req.send(null); var headers = req.getAllResponseHeaders().toLowerCase(); alert(headers);

 43. 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?
 Answers: • body onload="message()"

 44. Which of the following is the most secure and efficient way of declaring an array?
 Answers: • var a = []

 45. Which of the following Regular Expression pattern flags is not valid?
 Answers: • p

 46. Which of the following built-in functions is used to access form elements using their IDs?
 Answers: • getElementById(id)

 47. Which of the following statements is correct?
 Answers: • Undefined object properties can be checked using the following code: if (typeof something === "undefined") alert("something is undefined");

 48. Which of the following correctly uses a timer with a function named rearrange()?
 Answers: • tmr=setTimeout("rearrange ()",1)

 49. Which of the following can be used to escape the ' character?
 Answers: • \

 50. 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?
 Answers: • onblur

 51. When setting cookies with JavaScript, what will happen to the cookies.txt data if the file exceeds the maximum size?
 Answers: • The file is truncated to the maximum length.

 52. Which of the following are not global methods and properties in E4X?
 Answers: • setName() and setNamespace()

 53. 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?
 Answers: • <p onmouseover="style.color='blue'" onmouseout="style.color='black'"> The text of the paragraph..</p>

 54. 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']]]]
 Answers: • It makes it difficult for a third-party to insert the JSON response into an HTML document with a <script> tag.

 55. Consider the three variables:

 someText = 'JavaScript1.2';
 pattern = /(\w+)(\d)\.(\d)/i;
 outCome = pattern.exec(someText);

 What does outCome[0] contain?
 Answers: • JavaScript1.2

 56. 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>
 Answers: • window['foo']['bar']['baz']();

 57. Which of the following determines whether cookies are enabled in a browser or not?
 Answers: • (navigator.cookieEnabled)? true : false

 58. Which of the following options can be used for adding direct support for XML to JavaScript?
 Answers: • E4X

 59. Which of the following will detect which DOM element has the focus?
 Answers: • document.activeElement

 60. Which of the following will randomly choose an element from an array named myStuff, given that the number of elements changes dynamically?
 Answers: • randomElement = myStuff[Math.floor(Math.random() * myStuff.length)];

 61. How can global variables be declared in JavaScript?
 Answers: • Declare the variable between the 'script' tags, and outside a function to make the variable global

 62. Which of the following objects in JavaScript contains the collection called "plugins"?
 Answers: • Navigator

 63. 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());
 Answers: • firststep1second

 64. Which of the following methods will copy data to the Clipboard?
 Answers: • execCommand('Copy')

 65. Which of the following code snippets trims whitespace from the beginning and end of the given string str?
 Answers: • str.replace(/^\s+|\s+$/g, '');

 66. What is the difference between call() and apply()?
 Answers: • The call() function accepts an argument list of a function, while the apply() function accepts a single array of arguments.

 67. 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>
 Answers: • The second code is more efficient as it employs object caching.

 68. What is the meaning of obfuscation in JavaScript?
 Answers: • Making code unreadable using advanced algorithms.

 69. Which of the following JavaScript Regular Expression modifiers finds one or more occurrences of a specific character in a string?
 Answers: • +

 70. Which of the following is not a valid JavaScript operator?
 Answers: • ^

 71. Which of the following code snippets returns "[object object]"?
 Answers: • <script> var o = new Object(); o.toString(); </script>

 72. Which of the following can be used to invoke an iframe from a parent page?
 Answers: • window.frames

 73. Select the following function that shuffles an array?
 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; }

 74. Which of the following code snippets removes objects from an associative array?
 Answers: • delete array["propertyName"];

 75. What is the error in the statement: var charConvert = toCharCode('x');?
 Answers: • toCharCode() is a non-existent method.

 76. What value would JavaScript assign to an uninitialized variable?
 Answers: • undefined

 77. 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;
 }
 Answers: • It checks if an array contains 'obj'.

 78. 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?
 Answers: • The paragraph.

 79. Which of the following code snippets gets an image's dimensions (height & width) correctly?
 Answers: • var img = document.getElementById('imageid'); var width = img.clientWidth; var height = img.clientHeight;

 80. Which of the following are correct values of variableC, and why?

 <script>
 variableA = [6,8];
 variableB =[7,9];
 variableC = variableA + variableB;
 </script>
 Answers: • 6, 87 and 9. The + operator is not defined for arrays, and it concatenates strings, so it converts the arrays to strings.

 81. 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?
 Answers: • var e = document.getElementById("ddlViewBy"); var strUser = e.options[e.selectedIndex].value;

 82. var profits=2489.8237

 Which of the following code(s) produces the following output?

 output : 2489.824
 Answers: • profits.toFixed(3)

 83. A form contains two fields named id1 and id2. How can you copy the value of the id2 field to id1?
 Answers: • document.forms[0].id1.value=document.forms[0].id2.value

 84. 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>
 Answers: • <script> var button = document.getElementById('toggle'); button.onclick = function() { terd.style.backgroundColor = terd.style.backgroundColor == 'blue' ? 'red' : 'blue'; }; </script>

 85. How can the user's previously navigated page be determined using JavaScript?
 Answers: • Using the window object

 86. Which of the following is not a valid method for looping an array?
 Answers: • var a= [1,2]; a.loop( function(item) { alert(item); })

 87. Which of the following correctly sets a class for an element?
 Answers: • document.getElementById(elementId).setAttribute("className", "Someclass");

 88. An HTML form contains 10 checkboxes all named "chkItems". Which JavaScript function can be used for checking all the checkboxes together?
 Answers: • function CheckAll() { for (z = 0; z < document.forms[0].chkItems.length; z++) { document.forms[0].chkItems[z].checked=true } }

No comments:

Post a Comment