• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Script Interview Questions Answers

Question - 71 : - Can javascript code be broken in different lines?

Answer - 71 : - Breaking is possible within a string statement by using a backslash \ at the end but not within any other javascript statement. that is , document.write("Hello \ world"); is possible but not document.write \ ("hello world");

Question - 72 : - How to associate functions with objects using JavaScript?

Answer - 72 : - Let's now create a custom "toString()" method for our movie object. We can embed the function directly in the object like this. <script type="text/javascript"> function movie(title, director) { this.title = title; this.director = director; this.toString = function movieToString() { return("title: "+this.title+" director: "+this.director); } } var narnia = new movie("Narni","Andrew Adamson"); document.write(narnia.toString()); </script> This produces title: Narni director: Andrew Adamson Or we can use a previously defined function and assign it to a variable. Note that the name of the function is not followed by parenthesis, otherwise it would just execute the function and stuff the returned value into the variable. <script type="text/javascript"> function movieToString() { return("title: "+this.title+" director: "+this.director); } function movie(title, director) { this.title = title; this.director = director; this.toString = movieToString; //assign function to this method pointer } var aliens = new movie("Aliens","Cameron"); document.write(aliens.toString()); </script> This produces title: Aliens director: Cameron  

Question - 73 : - What does the "Access is Denied" IE error mean?

Answer - 73 : - The "Access Denied" error in any browser is due to the following reason. A javascript in one window or frame is tries to access another window or frame whose document's domain is different from the document containing the script.

Question - 74 : - How can JavaScript make a Web site easier to use? That is, are there certain JavaScript techniques that make it easier for people to use a Web site?

Answer - 74 : - JavaScript's greatest potential gift to a Web site is that scripts can make the page more immediately interactive, that is, interactive without having to submit every little thing to the server for a server program to re-render the page and send it back to the client. For example, consider a top-level navigation panel that has, say, six primary image map links into subsections of the Web site. With only a little bit of scripting, each map area can be instructed to pop up a more detailed list of links to the contents within a subsection whenever the user rolls the cursor atop a map area. With the help of that popup list of links, the user with a scriptable browser can bypass one intermediate menu page. The user without a scriptable browser (or who has disabled JavaScript) will have to drill down through a more traditional and time-consuming path to the desired content.

Question - 75 : - How to set the focus in an element using Javascript?

Answer - 75 : - <script> function setFocus() { if(focusElement != null) { document.forms[0].elements["myelementname"].focus(); } } </script>

Question - 76 : - How to convert numbers to strings using JavaScript?

Answer - 76 : - You can prepend the number with an empty string var mystring = ""+myinteger; or var mystring = myinteger.toString(); You can specify a base for the conversion, var myinteger = 14; var mystring = myinteger.toString(16); mystring will be "e".

Question - 77 : - decodeURI(), encodeURI()

Answer - 77 : - Many characters cannot be sent in a URL, but must be converted to their hex encoding. These functions are used to convert an entire URI (a superset of URL) to and from a format that can be sent via a URI. <script type="text/javascript"> var uri = "http://www.google.com/search?q=sonofusion Taleyarkhan" document.write("Original uri: "+uri); document.write("<br />encoded: "+encodeURI(uri)); </script>

Question - 78 : - What is the difference between undefined value and null value?

Answer - 78 : - (i)Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas null value has keyword called null (ii)typeof undefined variable or property returns undefined whereas typeof null value returns object

Question - 79 : - How to set a HTML document's background color?

Answer - 79 : - document.bgcolor property can be set to any appropriate color.

Question - 80 : - What is the data type of variables of in JavaScript?

Answer - 80 : - All variables are of object type in JavaScript.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners