• +91 9971497814
  • info@interviewmaterial.com

Java Script Interview Questions Answers

Question 1 : What and where are the best JavaScript resources on the Web?

Answer 1 : The Web has several FAQ areas on JavaScript. The best place to start is something called the meta-FAQ [14-Jan-2001 Editor's Note: I can't point to it anymore, it is broken!], which provides a high-level overview of the JavaScript help available on the Net. As for fact-filled FAQs, I recommend one maintained by Martin Webb and a mini-FAQ that I maintain. For interactive help with specific problems, nothing beats the primary JavaScript Usenet newsgroup, comp.lang.javascript. Depending on my work backlog, I answer questions posted there from time to time. Netscape and Microsoft also have vendor-specific developer discussion groups as well as detailed documentation for the scripting and object model implementations.

Question 2 : What is the difference between a web-garden and a web-farm?

Answer 2 : Web-garden - An IIS6.0 feature where you can configure an application pool as a web-garden and also specify the number of worker processes for that pool. It can help improve performance in some cases. Web-farm - a general term referring to a cluster of physically separate machines, each running a web-server for scalability and performance (contrast this with web-garden which refers to multiple processes on one single physical machine).

Question 3 : What are the problems associated with using JavaScript, and are there JavaScript techniques that you discourage?

Answer 3 : Browser version incompatibility is the biggest problem. It requires knowing how each scriptable browser version implements its object model. You see, the incompatibility rarely has to do with the core JavaScript language (although there have been improvements to the language over time); the bulk of incompatibility issues have to do with the object models that each browser version implements. For example, scripters who started out with Navigator 3 implemented the image rollover because it looked cool. But they were dismayed to find out that the image object wasn't scriptable in Internet Explorer 3 or Navigator 2. While there are easy workarounds to make this feature work on newer browsers without disturbing older ones, it was a painful learning experience for many. The second biggest can of worms is scripting connections between multiple windows. A lot of scripters like to have little windows pop up with navigation bars or some such gizmos. But the object models, especially in the older browser versions, don't make it easy to work with these windows the minute you put a user in front of them--users who can manually close windows or change their stacking order. More recently, a glitch in some uninstall routines for Windows 95 applications can disturb vital parts of the system Registry that Internet Explorer 4 requires for managing multiple windows. A scripter can't work around this problem, because it's not possible to detect the problem in a user's machine. I tend to avoid multiple windows that interact with each other. I think a lot of inexperienced Web surfers can also get confused by them.

Question 4 : Taking a developer’s perspective, do you think that that JavaScript is easy to learn and use?

Answer 4 : One of the reasons JavaScript has the word "script" in it is that as a programming language, the vocabulary of the core language is compact compared to full-fledged programming languages. If you already program in Java or C, you actually have to unlearn some concepts that had been beaten into you. For example, JavaScript is a loosely typed language, which means that a variable doesn't care if it's holding a string, a number, or a reference to an object; the same variable can even change what type of data it holds while a script runs. The other part of JavaScript implementation in browsers that makes it easier to learn is that most of the objects you script are pre-defined for the author, and they largely represent physical things you can see on a page: a text box, an image, and so on. It's easier to say, "OK, these are the things I'm working with and I'll use scripting to make them do such and such," instead of having to dream up the user interface, conceive of and code objects, and handle the interaction between objects and users. With scripting, you tend to write a _lot_ less code.

Question 5 : What Web sites do you feel use JavaScript most effectively (i.e., best-in-class examples)? The worst?

Answer 5 : The best sites are the ones that use JavaScript so transparently, that I'm not aware that there is any scripting on the page. The worst sites are those that try to impress me with how much scripting is on the page.

Question 6 : How about 2+5+"8"?

Answer 6 : Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.

Question 7 : What is the difference between SessionState and ViewState?

Answer 7 : ViewState is specific to a page in a session. Session state refers to user specific data that can be accessed across all pages in the web application.

Question 8 : What does the EnableViewStateMac setting in an aspx page do?

Answer 8 : Setting EnableViewStateMac=true is a security measure that allows ASP.NET to ensure that the viewstate for a page has not been tampered with. If on Postback, the ASP.NET framework detects that there has been a change in the value of viewstate that was sent to the browser, it raises an error - Validation of viewstate MAC failed. Use <%@ Page EnableViewStateMac="true"%> to set it to true (the default value, if this attribute is not specified is also true) in an aspx page.

Question 9 : How to shift and unshift using JavaScript?

Answer 9 : <script type="text/javascript"> var numbers = ["one", "two", "three", "four"]; numbers.unshift("zero"); document.write(" "+numbers.shift()); document.write(" "+numbers.shift()); document.write(" "+numbers.shift()); </script> This produces zero one two shift, unshift, push, and pop may be used on the same array. Queues are easily implemented using combinations.

Question 10 : How to Accessing Elements using javascript?

Answer 10 : To do something interesting with HTML elements, we must first be able to uniquely identify which element we want. In the example <body> <form action=""> <input type="button" id="useless" name="mybutton" value="doNothing" /> </form> </body> We can use the "getElementById" method (which is generally preferred) document.getElementById("useless").style.color = "red"; or we can use the older hierarchical navigation method, document.forms[0].mybutton.style.color = "blue"; Notice that this uses the "name" attribute of the element to locate it. # Example of Accessing Elements in a DOM. <script type="text/javascript" > function showStatus() { var selectWidget = document.forms.beerForm.elements["beer"]; var myValue = selectWidget.options[selectWidget.selectedIndex].value; alert('You drank a \"'+ myValue +"\""); return true; } </script> <form name="beerForm" action=""> <select name="beer"> <option selected="selected">Select Beer</option> <option>Heineken</option> <option>Amstel Light</option> <option>Corona</option> <option>Corona Light</option> <option>Tecate</option> </select> <input type="button" name="submitbutton" value="Drink" onclick="showStatus()" /> </form>

Java Script Contributors


Share your email for latest updates


Our partners