Upwork Test Answer JavaScript 1.8 Skill Test (Latest)

Upwork Test Answers of JavaScript 1.8 Skill Test (Latest)Question: 01
Analyze the following code snippet. What will be the output of this code?

<html>
<body>
<script type="text/javascript">
var str = "The drain of the plane is plain";
var patt1 =/ain/g;
document.write(str.match(patt1));
</script>
</body>
</html>


a. 1
b. ain
c. 7, 29
d. 7
e. ain, ain
Answer: e. ain, ain


Question: 02
Which of the following is the correct syntactical representation of a generator expression in JavaScript?

a. var doubles = [i * 2 for (i in it)];
b. var doubles = [i * 2 for [i in it]];
c. var doubles = (i * 2 for (i in it));
d. var doubles = {i * 2 for (i in it)};
Answer: c. var doubles = (i * 2 for (i in it));


Question: 03
What is the output of the following JavaScript code?

s2 = new String("2 + 2")
document.write(eval(s2));

a. 4
b. 2+2
c. Error
d. None of the above
Answer: b. 2+2


Question: 04
Consider the following code snippet. Which of the given options would be used in E4X to change the color of the descendant node chair?

var element = <Home>
    <Room>
    <Furniture>
    <chair color="Brown"/>
    </Furniture>
    </Room>
    </Home>

a. element.chair.color="light brown"
b. element.chair.@color="light brown"
c. element..chair.@color="light brown"
Answer: a. element.chair.color="light brown"


Question: 05
Consider the code snippet below. Which of the given options represents the correct sequence of outputs when this code is executed in E4X?

var p1 = <p>Kibology for all.</p>;
  alert(p1.name().uri);
  default xml namespace = 'http://www.w3.org/1999/xhtml';
  var p2 = <p>Kibology for all.</p>;
  alert(p2.name().uri);
  default xml namespace = '';
  var p3 = <p>Kibology for all.</p>;
  alert(p3.name().uri);

a. '',http://www.w3.org/1999/xhtml,''
b. '','',''
c. '',http://www.w3.org/1999/xhtml,http://www.w3.org/1999/xhtml
d. None of the above
Answer: d. None of the above


Question: 06
Which of the following is not a valid JavaScript operator?
a. *=
b. /=
c. %=
d. ^+
Answer: d. ^+


Question: 07
Which of the following is not a valid String method?
a. link()
b. italics()
c. str()
d. sup()
Answer: c. str()


Question: 08
Which of the following methods is used to add and/or remove elements from an array and modify them in place?
a. push
b. slice
c. join
d. splice
Answer: d. splice


Question: 09
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. $
e. a and b
f. c and d
Answer: e. a and b


Question: 10
Which of the following is not a valid Date Object method in JavaScript?
a. parse()
b. setDay()
c. setTime()
d. valueOf()
Answer: c. setTime()


Question: 11
Which of the following results is returned by the JavaScript operator "typeof" for the keyword "null"?
a. function
b. object
c. string
d. number
Answer: b. object


Question: 12
Which of the following can be used to create attribute values by placing variables and expressions within them?
a. []
b. ()
c. {}
d. <>
Answer: d. <>


Question: 13
What will the function NaN return for the condition NaN == NaN?
a. true
b. false
c. error
d. 0
Answer: b. false


Question: 14
Which of the following modifiers must be set if we use the Javascript lastIndex Object Property during pattern matching?
a. i
b. m
c. g
d. s
Answer: d. s


Question: 15
Which of the following two JavaScript code snippets is the more efficient and why?

CODE SNIPPET 1
<script language="javascript">
    for(i=0;i<document.images.length;i++)
    document.images[i].src="blank.gif";
</script>
CODE SNIPPET 2
<script language="javascript">
    var theimages = document.images;
    for(i=0;i<theimages.length;i++)
    theimages[i].src="blank.gif";
</script>

a. Both codes are equally efficient.
b. The first code is more efficient because it contains less code.
c. The first code is more efficient because it employs object caching.
d. The second code is more efficient because it employs object caching.
Answer: d. The second code is more efficient because it employs object caching.


Question: 16
Which of the following is used to solve the problem of enumerations in JavaScript?
a. let
b. Regex
c. Generators
d. E4X
Answer: c. Generators


Question: 17
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.
a. True
b. False
Answer: b. False


Question: 18
Which of the given options represents the correct length when alert(Emp..*.length()); is applied to the following code?

var Emp = <Emp>
  <name>Mark</name>
  <likes>
    <os>Linux</os>
    <browser>Firefox</browser>
    <language>JavaScript</language>
    <language>Python</language>
  </likes>
</Emp>

a. 11
b. 5
c. 6
d. 12
Answer: a. 11


Question: 19
Analyze the following code snippet. What will be the output of this code?

<html>
<body>
<script type="text/javascript">
var str = "Visit Gardens(now)";
var patt1 = new RegExp("(now)", "g");
patt1.test(str);
document.write(RegExp.lastParen);
</script>
</body>
</html>

a. now
b. (now)
c. 15
d. 19
Answer: a. now


Question: 20
Which of the following is the correct way to create an XML object in E4X?
a. var languages = new XML('JavaScriptPython');
b. var languages XML = new XML('JavaScriptPython');
c. var languages =
    JavaScript
    Python
    ;
d. All of the above are correct.
e. a and c
f. b and c
Answer: e. a and c


Question: 21
Which of the following Array methods in JavaScript runs a function on every item in the Array and collects the result from previous calls, but in reverse?
a. reduce()
b. reduceRight()
c. reverse()
d. pop()
Answer: c. reverse()


Question: 22
Which of the following can be achieved using JavaScript?
a. Reading or writing from external files
b. Accessing or modifying browser settings
c. Launching the default email application of the client
d. All of the above can be achieved using JavaScript.
Answer: d. All of the above can be achieved using JavaScript.


Question: 23
Which of the following objects is the top-level object in the JavaScript hierarchy?
a. Navigator
b. Screen
c. Window
d. Document
Answer: c. Window


Question: 24
Which of the following Javascript Regular Expression modifiers finds one or more occurrences of a specific character in a string?
a. ?
b. *
c. +
d. #
Answer: a. ?


Question: 25
Which of the following is the correct syntax for using the Javascript exec() object method?
a. RegExpObject.exec()
b. RegExpObject.exec(string)
c. RegExpObject.exec(parameter1,parameter2)
d. None of the above
Answer: b. RegExpObject.exec(string)


Question: 26
Analyze the following code using the source property of Regular Expressions. What will be the output of the below code snippet?

<html>
<body>
<script type="text/javascript">
var str = "Visit Garden\Showcase";
var patt1 = new RegExp("en\S","g");
document.write("The regular expression is: " + patt1.source);
</script>
</body>
</html>

a. The regular expression is: en\S
b. The regular expression is: 11
c. The regular expression is: enS
d. The regular expression is: 10
Answer: c. The regular expression is: enS


Question: 27
Which of the following options can be used for adding direct support for XML to JavaScript?
a. E4X
b. regex
c. Generators and Iterators
d. let
Answer: a. E4X


Question: 28
Which of the following options is used to access the attributes in E4X?
a. @
b. ::
c. #
d. *
Answer: a. @


Question: 29
Which of the following statements regarding let in JavaScript is not correct?
a. The let definition defines variables whose scope is constrained to the block in which they're defined. This syntax is very much like the syntax used for var.
b. The let expression lets you establish variables scoped only to a single expression.
c. The let keyword provides a way to associate values with variables within the scope of a block, and affects the values of like-named variables outside the block.
d. You can use let to establish variables that exist only within the context of a for loop.
Answer: c. The let keyword provides a way to associate values with variables within the scope of a block, and affects the values of like-named variables outside the block.


Question: 30
Which of the following are not global methods and properties in E4X?
a. ignoreComments
b. ignoreWhiteSpace
c. setName()
d. setNamespace()
e. a and b
f. c and d
Answer: f. c and d


Question: 31
What will be the output of the following code?

  var x = 5;
  var y = 0;
  document.write( let(x = x + 10, y = 12) x+y + ",");
  document.write(x+y);

a. 27,5
b. 22,5
c. 27,22
d. None of the above
Answer: a. 27,5


Question: 32
Which of the following is not a valid method in generator-iterator objects in JavaScript?
a. send()
b. throw()
c. next()
d. stop()
Answer: a. send()


Question: 33
Using the concept of "iterators" and "generators" in JavaScript, what will be the output of the following code?

function testGenerator()
{
  yield "first";
document.write("step1");
  yield "second";
document.write("step2");
  yield "third";
document.write("step3");
  }
var g = testGenerator();
document.write(g.next());
document.write(g.next());

a. firststep1second
b. step1step2
c. step1
d. step1step2step3
Answer: c. step1


Question: 34
Which of the following DOM objects can be used to determine the resolution of the screen?
a. It is not possible to determine the resolution of the screen.
b. Screen object
c. Document object
d. Window object
e. None of the above
Answer: b. Screen object


Question: 35
Analyze the following code snippet. What will be the output of this code?

<html>
<body>
<script type="text/javascript">
var str = "The rose";
var patt1 = new RegExp("rose", "g");
patt1.test(str);
document.write("rose found. index now at: " + patt1.lastIndex);
</script>
</body>
</html>

a. rose found. index now at: 5
b. rose found. index now at: 4
c. rose found. index now at: 8
d. No output
Answer: c. rose found. index now at: 8


Question: 36
Which of the following options can be used to delete a child node of an XML object in E4X?
a. delete xmlobject.child;
b. delete xmlobject.child[0];
c. delete xmlobject.@attribute;
d. All of the above
Answer: d. All of the above


Question: 37
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>

a. I
b. Is
c. s
d. I,s,
Answer: a. I


Question: 38
Consider the code below. What will be the final value of the variable "apt"?

var apt=2;
apt=apt<<2;

a. 2
b. 4
c. 6
d. 8
e. 16
Answer: d. 8


Question: 39
Is the following statement true or false?
A function becomes a generator if it contains one or more yield statements.
a. True
b. False
Answer: a. True


Question: 40
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>

a. The code will cause an error alert to be displayed if a numeric character is entered, and the numeric character is removed.
b. The code will cause an error alert to be displayed if a non-numeric character is entered, and the non-numeric character is removed.
c. The code will cause an error alert to be displayed if a numeric character is entered, and the value of textbox is reset.
d. The code will cause an error alert to be displayed if a non-numeric character is entered, and the value of textbox is reset.
Answer: a. The code will cause an error alert to be displayed if a numeric character is entered, and the numeric character is removed.


Question: 41
Analyze the following code snippet. What will be the output of this code?

<html>
<body>
<script type="text/javascript">
var str = "Visit Gardens(now)";
var patt1 = new RegExp("(now)", "g");
patt1.test(str);
document.write(RegExp.lastParen);
</script>
</body>
</html>

a. no
b. (no)
c. 15
d. 19
Answer: a. no


Question: 42
Which of the following is the correct method for getting the date of February 1 of the current year into a variable called "newDate"?
a. var d = new Date();
    newDate=new Date(d.getFullYear(), 1, 2);
b. var d = new Date();
    newDate=new Date(d.getFullYear(), 2, 1);
c. var d = new Date();
    newDate=new Date(d.getFullYear(), 1, 1);
d. var d = new Date();
    newDate= (d.getFullYear(), 1, 1);
Answer: c. var d = new Date();
                 newDate=new Date(d.getFullYear(), 1, 1);


Question: 43
Which of the following can be used to create attribute values by placing variables and expressions within them?
a. []
b. ()
c. {}
d. <>
Answer: c. {}


Question: 44
Which of the following Javascript Regular Expression Character Classes finds any non-digit character in a given string?
a. \W
b. \S
c. \B
d. \D
Answer: d. \D


Question: 45
Which of the following objects in JavaScript contains the collection called "plugins"?
a. Location
b. Window
c. Screen
d. Navigator
Answer: b. Window


Question: 46
Which of the following Javascript Regular Expression object methods is used to search a string for a specified value and return the result as true or false?
a. exec()
b. compile()
c. return()
d. test()
Answer: d. test()


Question: 47
Which of the following methods is not a valid Array object method in JavaScript?
a. reverse
b. shift
c. unshift
d. splice
e. All of the above are valid.
Answer: e. All of the above are valid.


Question: 48
In an HTML page, the form tag is defined as follows:

<form onsubmit="return Validate()" action="http://www.mysite.com/">
The validate() function is intended to prevent the form from being submitted if the name field in the form is empty. What will the validate() function look like?

a. <script type="text/javascript">
    function Validate()
    {
    if(document.forms[0].name.value == "")
        return true;
    else
        return false;}
    </script>
b. <script type="text/javascript">
    function Validate()
    {
    if(document.forms[0].name.value == "")
        return false;
    else
        return true;
    }
    </script>
c. <script type="text/javascript">
    function Validate()
    {
    if(document.forms[0].name== "")
        return false;
    else
    return true;
    }
    </script>
d. <script type="text/javascript">
    function Validate()
    {
    if(document.forms[0].name == "")
        return true;
    else
        return false;
    }
    </script>
Answer: d.

Don't Miss A Single Updates

Remember to check your email account to confirm your subscription.

Blogger
Disqus
Post a comment ➜

No Comment