Javascript Interview
Javascript Interview
Javascript Interview
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.
1.What will be result of following javascipt function
<script type="text/javascript">
var name = "CareerWebHelper";
function DisplayName () {
var name = "Sagar";
document.write(name);
}
</script>
A.CareerWebHelper
B.Sagar
C.Error
D.None of above
Click for answer
B.Sagar
2.What will be result of following javascipt function
<script type="text/javascript">
var name1 = "WCF MCQs";
function DisplayName () {
var name2 = " Online";
document.write(name1+name2);
}
</script>
A.WCF MCQsOnline
B.WCF MCQs Online
C.Object required error
D.Javascript Error
Click for answer
B.WCF MCQs Online
function DisplayName () {
var name2 = "ASP.NET MCQs";
if(name1 = "WPF Quiz")
document.write("name1 is not null");
else
document.write(name2);
}
</script>
A.ASP.NET MCQs
B.Error near if statement
C.name1 is not null
D.None of above
Click for answer
C.name1 is not null
7.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";
function DisplayName () {
var name2 = "ASP.NET MCQs";
(name1.replace('P','C')=="WCF Quiz"?document.write(name1):document.write(name2)
);
}
</script>
A.WPF Quiz
B.WCF Quiz
C.ASP.NET MCQs
Click for answer
A.WPF Quiz
8.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";
function DisplayName () {
var name2 = "ASP.NET MCQs";
name1=name1.replace('P','C');
document.write(name1);
}
</script>
A.WCF Quiz
B.WPF Quiz
C.ASP.NET MCQs
D.Error in statement near replace()
Click for answer
A.WCF Quiz