• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Script Interview Questions Answers

Question - 91 : - What does undefined value mean in javascript?

Answer - 91 : - Undefined value means the variable used in the code doesn't exist or is not assigned any value or the property doesn't exist.

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

Answer - 92 : - 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 - 93 : - How to comment javascript code?

Answer - 93 : - Use // for line comments and /* */ for block comments Name the numeric constants representing max,min values Number.MAX_VALUE Number.MIN_VALUE

Question - 94 : - how to force a page to go to another page using JavaScript ?

Answer - 94 : - <script language="JavaScript" type="text/javascript" ><!-- location.href="http://newhost/newpath/newfile.html"; //--></script>

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

Answer - 95 : - 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 - 96 : - Does javascript have the concept level scope?

Answer - 96 : - No. JavaScript does not have block level scope, all the variables declared inside a function possess the same level of scope unlike c,c++,java.

Question - 97 : - What does break and continue statements do?

Answer - 97 : - Continue statement continues the current loop (if label not specified) in a new iteration whereas break statement exits the current loop.

Question - 98 : - How to Accessing Elements using javascript?

Answer - 98 : - 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>

Question - 99 : - What can javascript programs do?

Answer - 99 : - Generation of HTML pages on-the-fly without accessing the Web server. The user can be given control over the browser like User input validation Simple computations can be performed on the client's machine The user's browser, OS, screen size, etc. can be detected Date and Time Handling

Question - 100 : - How can JavaScript be used to improve the "look and feel" of a Web site? By the same token, how can JavaScript be used to improve the user interface?

Answer - 100 : - On their own, Web pages tend to be lifeless and flat unless you add animated images or more bandwidth-intensive content such as Java applets or other content requiring plug-ins to operate (ShockWave and Flash, for example). Embedding JavaScript into an HTML page can bring the page to life in any number of ways. Perhaps the most visible features built into pages recently with the help of JavaScript are the so-called image rollovers: roll the cursor atop a graphic image and its appearance changes to a highlighted version as a feedback mechanism to let you know precisely what you're about to click on. But there are less visible yet more powerful enhancements to pages that JavaScript offers. Interactive forms validation is an extremely useful application of JavaScript. While a user is entering data into form fields, scripts can examine the validity of the data--did the user type any letters into a phone number field?, for instance. Without scripting, the user has to submit the form and let a server program (CGI) check the field entry and then report back to the user. This is usually done in a batch mode (the entire form at once), and the extra transactions take a lot of time and server processing power. Interactive validation scripts can check each form field immediately after the user has entered the data, while the information is fresh in the mind. Another helpful example is embedding small data collections into a document that scripts can look up without having to do all the server programming for database access. For instance, a small company could put its entire employee directory on a page that has its own search facility built into the script. You can cram a lot of text data into scripts no larger than an average image file, so it's not like the user has to wait forever for the data to be downloaded. Other examples abound, such as interactive tree-structure tables of contents. More modern scriptable browsers can be scripted to pre-cache images during the page's initial download to make them appear lickety-split when needed for image swapping. I've even written some multi-screen interactive applications that run entirely on the client, and never talk to the server once everything is downloaded.

Computer Contributors

Rajeev Katiyar
Yes Baroda

Share your email for latest updates


Our partners