Sunday, January 12, 2014

oDesk JavaScript 1.8 Test answer

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
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)};
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
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"
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);
b. '','',''
d. None of the above
Which of the following is not a valid JavaScript operator?
a. *=
b. /=
c. %=
d. ^+
Which of the following is not a valid String method?
a. link()
b. italics()
c. str()
d. sup()
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
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
Which of the following is not a valid Date Object method in JavaScript?
a. parse()
b. setDay()
c. setTime()
d. valueOf()
Which of the following results is returned by the JavaScript operator "typeof" for the keyword "null"?
a. function
b. object
c. string
d. number
Which of the following can be used to create attribute values by placing variables and expressions within them?
a. []
b. ()
c. {}
d. <>
What will the function NaN return for the condition NaN == NaN?
a. true
b. false
c. error
d. 0
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
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.
Which of the following is used to solve the problem of enumerations in JavaScript?
a. let
b. Regex
c. Generators
d. E4X
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
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
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
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
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()
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.
Which of the following objects is the top-level object in the JavaScript hierarchy?
a. Navigator
b. Screen
c. Window
d. Document
Which of the following Javascript Regular Expression modifiers finds one or more occurrences of a specific character in a string?
a. ?
b. *
c. +
d. #
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
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
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
Which of the following options is used to access the attributes in E4X?
a. @
b. ::
c. #
d. *
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.
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
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
Which of the following is not a valid method in generator-iterator objects in JavaScript?
a. send()
b. throw()
c. next()
d. stop()
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
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
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
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
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,
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
Is the following statement true or false?

A function becomes a generator if it contains one or more yield statements.
a. True
b. False
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.
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

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);
Which of the following can be used to create attribute values by placing variables and expressions within them?
a. []
b. ()
c. {}
d. <>
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
Which of the following objects in JavaScript contains the collection called "plugins"?
a. Location
b. Window
c. Screen
d. Navigator
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()
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.
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>
Which of the following is the correct way to create an XML object in E4X?
a. var languages = new XML('<languages     
    type="dynamic"><lang>JavaScript</lang><lang>Python</lang></languages>');
b. var languages XML = new XML('<languages   
    type="dynamic"><lang>JavaScript</lang><lang>Python</lang></languages>');
c. var languages = <languages type="dynamic">
    <lang>JavaScript</lang>
    <lang>Python</lang>
     </languages>;
d. All of the above are correct.
e. a and c
f. b and c
What does the following JavaScript code do? <head id="Head1" runat="server">
 
  <title></title>
  <script type="text/javascript">
    function validate() {
      var chk = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
      var ok = "yes";
      var temp;
      var field1 = document.getElementById("t1");
      var field = field1.value.substring(field1.value.length - 1, field1.value.length);
      if (chk.indexOf(field) == "-1") {
        alert("error");
        field1.value = (field1.value).slice(0, field1.value.length - 1);
      }
    }
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="t1" onkeyup="validate()" onkeypress ="validate()"/>
</form>
</body>
a. The code will cause an error alert to be displayed if a non alphabet character is entered.
b. The code will cause an error alert to be displayed if ALPHABET character is entered.
c. The code will cause NO error alert to be displayed if a numeric character is entered.
d. The code will cause NO error alert to be displayed if a NON ALPHABET character is entered.

No comments:

Post a Comment