0% found this document useful (0 votes)
693 views

Javascript Interview

The document contains 10 code snippets with multiple choice questions about JavaScript concepts like variables, functions, objects, and conditional statements. The code snippets demonstrate evaluating expressions, defining and invoking functions, concatenating strings, checking for equality, replacing strings, and more. The correct answers are provided with brief explanations.

Uploaded by

Warren Rivera
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
693 views

Javascript Interview

The document contains 10 code snippets with multiple choice questions about JavaScript concepts like variables, functions, objects, and conditional statements. The code snippets demonstrate evaluating expressions, defining and invoking functions, concatenating strings, checking for equality, replacing strings, and more. The correct answers are provided with brief explanations.

Uploaded by

Warren Rivera
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

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 String.prototype.concat('', arguments);
}
b. function concatenate()
{
return String.prototype.apply('', arguments);
}
c. function concatenate()
{

return String.concat.apply('', arguments);


}
d. function concatenate()
{
return String.prototype.concat.apply('', 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();
c.count()
d.count()
c.reset()
c.count()
d.count()
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.
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

3.What will be result of following javascipt function?


<script type="text/javascript">
var name1 = "WCF quiz";
function DisplayName () {
var name2 = "ASP.NET MCQs";
if(name1 != "")
document.write(name1);
else
document.write(name2);
}
</script>
A.Javascript Error at else statement
B.ASP.NET MCQs
C.WCF quiz
D.Javascript Error in if condition
Click for answer
C.WCF quiz
4.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WCF quiz";
function DisplayName () {
var name2 = "ASP.NET MCQs";
(name1 != ""?document.write(name2):document.write(name1));
}
</script>
A.WCF quiz
B.ASP.NET MCQs
C.Javascript Error near conditional statement
D.Nothing will happen
Click for answer
B.ASP.NET MCQs
5.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "";
function DisplayName () {
var name2 = "ASP.NET MCQs";
if(name1 = "")
document.write("name1 is null");
else
document.write(name2);
}
</script>
A.name1 is null
B.Error near name1 declaration
C.No result
D.ASP.NET MCQs
Click for answer
D.ASP.NET MCQs
6.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";

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

You might also like