• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Script Interview Questions Answers

Question - 11 : - How to disable an HTML object ?

Answer - 11 : - document.getElementById("myObject").disabled = true; To write messages to the screen without using "document.write()" ? Changing the contents of an element is a much better solution. When the method showStatus is invoked it will change the content of the span. ... function showStatus(message) { var element = document.getElementById("mystatus"); element.textContent = message; //for Firefox element.innerHTML = message; //for IE (why can't we all just get along?) return true; } ... <span id="mystatus">Test. </span> ...

Question - 12 : - How to create a function using function constructor?

Answer - 12 : - The following example illustrates this It creates a function called square with argument x and returns x multiplied by itself. var square = new Function ("x","return x*x");

Question - 13 : - What are undefined and undeclared variables?

Answer - 13 : - Undeclared variables are those that are not declared in the program (do not exist at all),trying to read their values gives runtime error.But if undeclared variables are assigned then implicit declaration is done . Undefined variables are those that are not assigned any value but are declared in the program.Trying to read such variables gives special value called undefined value.

Question - 14 : - What looping structures are there in JavaScript?

Answer - 14 : - for, while, do-while loops, but no foreach. To put a "close window" link on a page ? <a href='javascript:window.close()' class='mainnav'> Close </a>

Question - 15 : - How to embed javascript in a web page?

Answer - 15 : - javascript code can be embedded in a web page between <script langugage="javascript"></script> tags

Question - 16 : - What's Prototypes for JavaScript?

Answer - 16 : - Objects have "prototypes" from which they may inherit fields and functions. <script type="text/javascript"> function movieToString() { return("title: "+this.title+" director: "+this.director); } function movie(title, director) { this.title = title; this.director = director || "unknown"; //if null assign to "unknown" this.toString = movieToString; //assign function to this method pointer } movie.prototype.isComedy = false; //add a field to the movie's prototype var officeSpace = new movie("OfficeSpace"); var narnia = new movie("Narni","Andrew Adamson"); document.write(narnia.toString()); document.write(" Narnia a comedy? "+narnia.isComedy); officeSpace.isComedy = true; //override the default just for this object document.write(" Office Space a comedy? "+officeSpace.isComedy); </script>

Question - 17 : - What is the difference between an alert box and a confirmation box?

Answer - 17 : - An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel.

Question - 18 : - How to have an element invoke a javascript on selection, instead of going to a new URL: ?

Answer - 18 : - <script type="text/javascript"> function pseudoHitMe() { alert("Ouch!"); } </script> <a href="javascript:pseudoHitMe()">hit me</a>

Question - 19 : - How to convert a string to a number using JavaScript?

Answer - 19 : - You can use the parseInt() and parseFloat() methods. Notice that extra letters following a valid number are ignored, which is kinda wierd but convenient at times. parseInt("100") ==> 100 parseFloat("98.6") ==> 98.6 parseFloat("98.6 is a common temperature.") ==> 98.6 parseInt("aa") ==> Nan //Not a Number parseInt("aa",16) ==> 170 //you can supply a radix or base

Question - 20 : - How to have the status line update when the mouse goes over a link (The support of the status line is sporadic)?

Answer - 20 : - <a href="javascript.shtml" onmouseover="window.status='Hi There!';return true" onmouseout="window.status='';return true">Look at the Status bar</a> Look at the Status bar as your cursor goes over the link.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners