1.
Given the following code snippet, what is the scope of the variable pen on Line 1?
<script>
1. var pen = "ball point";
2. var pencil = "0.7mm
lead";
3. function writeIt()
4. {
5.
document.write(I
have a " + pen + " pen.");
6.
pen = "gel
ink";
7. document.write("You
have a " + pen + " pen.");
8.
var pencil =
"0.5mm lead";
9.
document.write("I
prefer pencils with " + pencil + ".");
10. }
<script>
A. global
B. local
C. value
D. reference
2. Given the following code snippet, what is the scope of the variable pencil on Line 8?
<script>
1. var pen = "ball point";
2. var pencil = "0.7mm
lead";
3. function writeIt()
4. {
5.
document.write(I
have a " + pen + " pen.");
6.
pen = "gel
ink";
7. document.write("You
have a " + pen + " pen.");
8.
var pencil =
"0.5mm lead";
9.
document.write("I
prefer pencils with " + pencil + ".");
10. }
<script>
A. global
B. local
C. value
D. reference
3. Which of the following is not a valid function call?
A. count = parseInt(num);
B. document.write(getNum());
C. getNum(num) = 16;
D. getNum();
4. Which of the following will create a Boolean object named TorF?
A. var TorF = "true";
B. var TorF = new Boolean();
C. var TorF = Boolean;
D. var TorF = new Bool;
5. Which is not a method of the Date() object?
A. getDay()
B. getHours()
C. getTime()
D. getFullMonth()
1)
1.
Given the following code snippet, what is the scope of the variable pen on Line 1?
<script>
1. var pen = "ball point";
2. var pencil = "0.7mm lead";
3. function writeIt()
4. {
5.
document.write(I
have a " + pen + " pen.");
6. pen = "gel
ink";
7. document.write("You
have a " + pen + " pen.");
8. var pencil
= "0.5mm lead";
9.
document.write("I
prefer pencils with " + pencil + ".");
10. }
<script>
A. global ,because it is not defined inside the function ,So it is global .It can be used either inside or outside the function .i.e. in the entire program
======================================================================
2. Given the following code snippet, what is the scope of the variable pencil on Line 8?
<script>
1. var pen = "ball point";
2. var pencil = "0.7mm lead";
3. function writeIt()
4. {
5.
document.write(I
have a " + pen + " pen.");
6. pen = "gel
ink";
7. document.write("You
have a " + pen + " pen.");
8. var pencil
= "0.5mm lead";
9.
document.write("I
prefer pencils with " + pencil + ".");
10. }
<script>
B.Local
Because the variable pencil declared on the line 8 , can be used only inside the writeIt function.Where as the pencil on Line 2 is global varaible.
===============================================================
3. Which of the following is not a valid function call?
The parseInt() function parses a string and returns an integer.
A. count = parseInt(num); //we need to pass the string for parse int (or a number in double quotes)
=====================================================================
4. Which of the following will create a Boolean object named TorF?
var TorF = new Boolean();
Syntax to create boolean object: var val = new Boolean(value);
===========================================================================
5. Which is not a method of the Date() object?
D. getFullMonth()
we dont have this method in the date object.where as, getTime() gives the time getDate() returns the day of the month for the specified date according to local time and getDay() returns the day of the week for the specified date according to local time.
1. Given the following code snippet, what is the scope of the variable pen on Line...
Ensure the following compiles 5. Variable scope (1 mark) Some variables are only accessible while executing specific code. Global variables are often thought of as evil because the state of a system can be altered making functions execute differently when it isn't expected. There is also the issue of block scope. For an example of block scope, see the file below. Notice that you don't get an error because the code uses the correct syntax. Although the syntax is correct,...