Page 1
JavaScript Test Latest Questions and
Correct Answers
6.1 In the following line the word document is a(n) ______
that resides in the computer's memory.
document.writeln("Hello World");
a) attribute
b) behavior
c) object
d) method
Ans: c) Object
6.2 In the following line, the word writeln is a(n) _________
that performs a task or action in the script.
document.writeln("Hello World");
a) structure
b) collection
c) object
d) method
Ans: d) Method
6.3 Consider the following HTML5 code.
<html>
, Page 2
<script type = "text/javascript">
<!--
<!-- document.writeln("Hello World"); -->
//-->
</script>
</html>
What would a browser capable of scripting display when
executing this code?
a) document.writeln("Hello World");
b) nothing
c) Hello World
d) <html>
<script type = "text/javascript">
<!--
<!-- document.writeln("Hello World </p>");
//-->
</script>
</html>
Ans: b) Nothing
6.4 Which of the following statements would correctly print
out the sentence "Hello World" in blue?
, Page 3
a) document.write( "<p style = \"color: blue\");
document.write( "Hello World >");
b) document.write( "<p> style = \"color: blue\" Hello World
</p>);
c) document.write( "<p style = \"color: blue\" Hello World +
"</p>");
d) document.write( "<p style = \"color: blue\">");
document.write( "Hello World </p>");
Ans: d) document.write( "<p style = \"color: blue\">");
document.write( "Hello World </p>");
6.5 An alert dialog displaying the text "Welcome!" is created
by calling _________.
a) window.alert( "Welcome!" );
b) alert.window( "Welcome!" );
c) window( "alert = \"Welcome!\"" );
d) window( "<alert> Welcome! </alert>" );
Ans: a) window.alert( "Welcome!" );
6.6 Consider the following script. What is wrong with the
following code?
<script type = "text/javascript">
var firstNumber;
, Page 4
thirdNumber;
firstNumber = window.prompt("Enter an integer", "0");
secondNumber = window.prompt("Enter an integer", "0");
thirdNumber = firstNumber + secondNumber;
</script>
a) thirdNumber in line 7 must be in quotes.
b) The words Enter an integer in line 6 should not be in
quotes.
c) The word thirdnumber in line 3 should have a comma after
it.
d) The word var must be placed before thirdNumber in line 3.
Ans: d) The word var must be placed before
thirdNumber in line 3.
6.7 Which of the following is not a valid variable name?
a) Tax1
b) eightball_8
c) 12footage
d) pageNumber1200
Ans: c) 12footage
JavaScript Test Latest Questions and
Correct Answers
6.1 In the following line the word document is a(n) ______
that resides in the computer's memory.
document.writeln("Hello World");
a) attribute
b) behavior
c) object
d) method
Ans: c) Object
6.2 In the following line, the word writeln is a(n) _________
that performs a task or action in the script.
document.writeln("Hello World");
a) structure
b) collection
c) object
d) method
Ans: d) Method
6.3 Consider the following HTML5 code.
<html>
, Page 2
<script type = "text/javascript">
<!--
<!-- document.writeln("Hello World"); -->
//-->
</script>
</html>
What would a browser capable of scripting display when
executing this code?
a) document.writeln("Hello World");
b) nothing
c) Hello World
d) <html>
<script type = "text/javascript">
<!--
<!-- document.writeln("Hello World </p>");
//-->
</script>
</html>
Ans: b) Nothing
6.4 Which of the following statements would correctly print
out the sentence "Hello World" in blue?
, Page 3
a) document.write( "<p style = \"color: blue\");
document.write( "Hello World >");
b) document.write( "<p> style = \"color: blue\" Hello World
</p>);
c) document.write( "<p style = \"color: blue\" Hello World +
"</p>");
d) document.write( "<p style = \"color: blue\">");
document.write( "Hello World </p>");
Ans: d) document.write( "<p style = \"color: blue\">");
document.write( "Hello World </p>");
6.5 An alert dialog displaying the text "Welcome!" is created
by calling _________.
a) window.alert( "Welcome!" );
b) alert.window( "Welcome!" );
c) window( "alert = \"Welcome!\"" );
d) window( "<alert> Welcome! </alert>" );
Ans: a) window.alert( "Welcome!" );
6.6 Consider the following script. What is wrong with the
following code?
<script type = "text/javascript">
var firstNumber;
, Page 4
thirdNumber;
firstNumber = window.prompt("Enter an integer", "0");
secondNumber = window.prompt("Enter an integer", "0");
thirdNumber = firstNumber + secondNumber;
</script>
a) thirdNumber in line 7 must be in quotes.
b) The words Enter an integer in line 6 should not be in
quotes.
c) The word thirdnumber in line 3 should have a comma after
it.
d) The word var must be placed before thirdNumber in line 3.
Ans: d) The word var must be placed before
thirdNumber in line 3.
6.7 Which of the following is not a valid variable name?
a) Tax1
b) eightball_8
c) 12footage
d) pageNumber1200
Ans: c) 12footage