1.
Consider the following code snippet :
var grand_Total=eval("10*10+5");
The output for the above statement would be :
a. 10*10+5
b. 105 as a string
c. 105 as an integer value
d. Exception is thrown
View Answer
Answer : c
Explanation : Even if the string value passed as a parameter to eval does repres
ent a numeric value the use of eval() results in an error being generated.
2. Do functions in JavaScript necessarily return a value ?
a. It is mandatory
b. Not necessary
c. Few functions return values by default
d. All of the above
View Answer
Answer : c
Explanation : None.
3. Consider the following code snippet :
var tensquared = (function(x) {return x*x;}(10));
Will the above code work ?
a. Yes, perfectly
b. Error
c. Exception will be thrown
d. Memory leak
View Answer
Answer : a
Explanation : Function name is optional for functions defined as expressions. Fu
nction expressions are sometimes defined and immediately invoked.
4. Consider the following code snippet :
var string2Num=parseInt("123xyz");
The result for the above code snippet would be :
a. 123
b. 123xyz
c. Exception
d. NaN
View Answer
Answer : b
Explanation : The parseInt() function returns the first integer contained in the
string or 0 if the string does not begin with an integer.
5. The one-liner code that concatenates all strings passed into a function is
a. function concatenate()
{
return [Link]('', arguments);
}
b. function concatenate()
{
return [Link]('', arguments);
}
c. function concatenate()
{
return [Link]('', arguments);
}
d. function concatenate()
{
return [Link]('', arguments);
}
View Answer
Answer : d
Explanation : None
6. If you have a function f and an object o, you can define a method named m of
o with
a. o.m=m.f;
b. o.m=f;
c. o=f.m;
d. o=f;
View Answer
Answer : a
Explanation : A method is nothing more than a JavaScript function that is stored
in a property of an object. If you have a function f and an object o, you can d
efine a method named m of o with the following line:
o.m = f;
7. For the below mentioned code snippet:
var o = new Object();
The equivalent statement is:
a. var o = Object();
b. var o;
c. var o= new Object;
d. Object o=new Object();
View Answer
Answer : c
Explanation : You can always omit a pair of empty parentheses in a constructor i
nvocation.
8. What is the difference between the two lines given below ?
!!(obj1 && obj2);
(obj1 && obj2);
a. Both the lines result in a boolean value True
b. Both the lines result in a boolean value False
c. Both the lines checks just for the existence of the object alone
d. The first line results in a real boolean value whereas the second line merely
checks for the existence of the objects
View Answer
Answer : d
Explanation : None.
9. Consider the following code snippet :
var c = counter(), d = counter();
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
The state stored in d is :
a. 1
b. 0
c. Null
d. Undefined
View Answer
Answer : a
Explanation : The state stored in d is 1 because d was not reset.
10. Consider the following code snippet :
function constfuncs()
{
var funcs = [];
for(var i = 0; i < 10; i++)
funcs[i] = function() { return i; };
return funcs;
}
var funcs = constfuncs();
funcs[5]()
What does the last statement return ?
a. 9
b. 0
c. 10
d. None of the above
View Answer
Answer : c
Explanation : The code above creates 10 closures, and stores them in an array. T
he closures are all defined within the same invocation of the function, so they
share access to the variable i. When constfuncs() returns, the value of the vari
able i is 10, and all 10 closures share this value. Therefore, all the functions
in the returned array of functions return the same value.
[Link] will be result of following javascipt function
<script type="text/javascript">
var name = "CareerWebHelper";
function DisplayName () {
var name = "Sagar";
[Link](name);
}
</script>
[Link]
[Link]
[Link]
[Link] of above
Click for answer
[Link]
[Link] will be result of following javascipt function
<script type="text/javascript">
var name1 = "WCF MCQs";
function DisplayName () {
var name2 = " Online";
[Link](name1+name2);
}
</script>
[Link] MCQsOnline
[Link] MCQs Online
[Link] required error
[Link] Error
Click for answer
[Link] MCQs Online
[Link] will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WCF quiz";
function DisplayName () {
var name2 = "[Link] MCQs";
if(name1 != "")
[Link](name1);
else
[Link](name2);
}
</script>
[Link] Error at else statement
[Link] MCQs
[Link] quiz
[Link] Error in if condition
Click for answer
[Link] quiz
[Link] will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WCF quiz";
function DisplayName () {
var name2 = "[Link] MCQs";
(name1 != ""?[Link](name2):[Link](name1));
}
</script>
[Link] quiz
[Link] MCQs
[Link] Error near conditional statement
[Link] will happen
Click for answer
[Link] MCQs
[Link] will be result of following javascipt function?
<script type="text/javascript">
var name1 = "";
function DisplayName () {
var name2 = "[Link] MCQs";
if(name1 = "")
[Link]("name1 is null");
else
[Link](name2);
}
</script>
A.name1 is null
[Link] near name1 declaration
[Link] result
[Link] MCQs
Click for answer
[Link] MCQs
[Link] will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";
function DisplayName () {
var name2 = "[Link] MCQs";
if(name1 = "WPF Quiz")
[Link]("name1 is not null");
else
[Link](name2);
}
</script>
[Link] MCQs
[Link] near if statement
C.name1 is not null
[Link] of above
Click for answer
C.name1 is not null
[Link] will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";
function DisplayName () {
var name2 = "[Link] MCQs";
([Link]('P','C')=="WCF Quiz"?[Link](name1):[Link](name2)
);
}
</script>
[Link] Quiz
[Link] Quiz
[Link] MCQs
Click for answer
[Link] Quiz
[Link] will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";
function DisplayName () {
var name2 = "[Link] MCQs";
name1=[Link]('P','C');
[Link](name1);
}
</script>
[Link] Quiz
[Link] Quiz
[Link] MCQs
[Link] in statement near replace()
Click for answer
[Link] Quiz