• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Script Interview Questions Answers

Question - 41 : - How to setting a cookie with the contents of a textbox ?

Answer - 41 : - Values stored in cookies may not have semicolons, commas, or spaces. You should use the handy "escape()" function to encode the values, and "unescape()" to retrieve them. //Sets cookie of current value for myTextBox function TextBoxOnchange() { var myBox = window.document.getElementById(myTextBox"); document.cookie = "myTextBox="+ escape(myBox.value) + getExpirationString(); } //return a string like ";expires=Thu, 5 Jan 2006 16:07:52 UTC" function getExpirationString() { var exp = new Date(); var threemonths = exp.getTime()+(120*24*60*60*1000); exp.setTime(threemonths); return ";expires="+exp.toGMTString(); } This is called from the event handler in the HTML. <input name="myTextBox" type="text" id="myTextBox" onchange="javascript:TextBoxOnchange()" />

Question - 42 : - In a pop-up browser window, how do you refer to the main browser window that opened it?

Answer - 42 : - Use window.opener to refer to the main window from pop-ups.

Question - 43 : - How to access an external javascript file that is stored externally and not embedded?

Answer - 43 : - This can be achieved by using the following tag between head tags or between body tags. <script src="abc.js"></script>How to access an external javascript file that is stored externally and not embedded? where abc.js is the external javscript file to be accessed.

Question - 44 : - How to create an input box?

Answer - 44 : - prompt("What is your temperature?");

Question - 45 : - How to use strings as array indexes using JavaScript?

Answer - 45 : - Javascript does not have a true hashtable object, but through its wierdness, you can use the array as a hashtable. <script type="text/javascript"> var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"]; for(var i=0; i < days.length; i++) { days[days[i]] = days[i]; } document.write("days[\"Monday\"]:"+days["Monday"]); </script> This produces days["Monday"]:Monday

Question - 46 : - What does the delete operator do?

Answer - 46 : - The delete operator is used to delete all the variables and objects used in the program ,but it does not delete variables declared with var keyword.

Question - 47 : - How to shift and unshift using JavaScript?

Answer - 47 : - <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 - 48 : - How do you convert numbers between different bases in JavaScript?

Answer - 48 : - Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);

Question - 49 : - How to test for bad numbers using JavaScript?

Answer - 49 : - the global method, "isNaN()" can tell if a number has gone bad. var temperature = parseFloat(myTemperatureWidget.value); if(!isNaN(temperature)) { alert("Please enter a valid temperature."); }

Question - 50 : - How to detect the operating system on the client machine?

Answer - 50 : - In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners