Javascript Interview

download Javascript Interview

If you can't read please download the document

description

refer

Transcript of Javascript Interview

1. Consider the following code snippet :var grand_Total=eval("10*10+5");The output for the above statement would be :a. 10*10+5b. 105 as a stringc. 105 as an integer valued. Exception is thrownView AnswerAnswer : cExplanation : Even if the string value passed as a parameter to eval does represent 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 mandatoryb. Not necessaryc. Few functions return values by defaultd. All of the aboveView AnswerAnswer : cExplanation : None.3. Consider the following code snippet :var tensquared = (function(x) {return x*x;}(10));Will the above code work ?a. Yes, perfectlyb. Errorc. Exception will be thrownd. Memory leakView AnswerAnswer : aExplanation : Function name is optional for functions defined as expressions. Function 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. 123b. 123xyzc. Exceptiond. NaNView AnswerAnswer : bExplanation : 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 isa. 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 AnswerAnswer : dExplanation : None6. If you have a function f and an object o, you can define a method named m of o witha. o.m=m.f;b. o.m=f;c. o=f.m;d. o=f;View AnswerAnswer : aExplanation : 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 define 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 AnswerAnswer : cExplanation : You can always omit a pair of empty parentheses in a constructor invocation.8. What is the difference between the two lines given below ?!!(obj1 && obj2);(obj1 && obj2);a. Both the lines result in a boolean value Trueb. Both the lines result in a boolean value Falsec. Both the lines checks just for the existence of the object aloned. The first line results in a real boolean value whereas the second line merely checks for the existence of the objectsView AnswerAnswer : dExplanation : 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. 1b. 0c. Nulld. UndefinedView AnswerAnswer : aExplanation : 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. 9b. 0c. 10d. None of the aboveView AnswerAnswer : cExplanation : The code above creates 10 closures, and stores them in an array. The 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 variable 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 functionvar name = "CareerWebHelper";function DisplayName () {var name = "Sagar"; document.write(name); }A.CareerWebHelperB.SagarC.ErrorD.None of above Click for answer B.Sagar2.What will be result of following javascipt functionvar name1 = "WCF MCQs";function DisplayName () {var name2 = " Online"; document.write(name1+name2); }A.WCF MCQsOnlineB.WCF MCQs Online C.Object required errorD.Javascript ErrorClick for answer B.WCF MCQs Online3.What will be result of following javascipt function?var name1 = "WCF quiz";function DisplayName () { var name2 = "ASP.NET MCQs";if(name1 != "") document.write(name1);elsedocument.write(name2); }A.Javascript Error at else statementB.ASP.NET MCQsC.WCF quiz D.Javascript Error in if conditionClick for answer C.WCF quiz4.What will be result of following javascipt function?var name1 = "WCF quiz";function DisplayName () { var name2 = "ASP.NET MCQs"; (name1 != ""?document.write(name2):document.write(name1));}A.WCF quizB.ASP.NET MCQs C.Javascript Error near conditional statementD.Nothing will happenClick for answer B.ASP.NET MCQs5.What will be result of following javascipt function?var name1 = "";function DisplayName () { var name2 = "ASP.NET MCQs"; if(name1 = "")document.write("name1 is null");elsedocument.write(name2); }A.name1 is nullB.Error near name1 declarationC.No resultD.ASP.NET MCQs Click for answer D.ASP.NET MCQs6.What will be result of following javascipt function?var name1 = "WPF Quiz";function DisplayName () { var name2 = "ASP.NET MCQs"; if(name1 = "WPF Quiz")document.write("name1 is not null");elsedocument.write(name2); }A.ASP.NET MCQsB.Error near if statementC.name1 is not null D.None of above Click for answer C.name1 is not null7.What will be result of following javascipt function?var name1 = "WPF Quiz";function DisplayName () { var name2 = "ASP.NET MCQs"; (name1.replace('P','C')=="WCF Quiz"?document.write(name1):document.write(name2));}A.WPF Quiz B.WCF QuizC.ASP.NET MCQsClick for answer A.WPF Quiz8.What will be result of following javascipt function?var name1 = "WPF Quiz";function DisplayName () { var name2 = "ASP.NET MCQs"; name1=name1.replace('P','C'); document.write(name1);}A.WCF Quiz B.WPF QuizC.ASP.NET MCQsD.Error in statement near replace()Click for answer A.WCF Quiz