Ans. A prompt box allows the user to enter input by providing a text box.
55. Can javascript code be broken in different lines?
Ans. 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" ); |
document.write \ ( "hello world" ); |
56. How you put a “close window” link on a page ?
Ans.
< a class = "mainnav" href = "javascript:window.close()" > Close </ a > |
57. How to hide javascript code from old browsers that dont run it?
Ans.Use the below specified style of comments
// <![CDATA[ javascript code goes here // ]]> |
< noscript >some html code</ noscript > |
58. Name the numeric constants representing max,min values.
Ans.
Number.MAX_VALUE Number.MIN_VALUE |
59. How to write messages to the screen without using “document.write()” ?
Ans. 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 > |
60. How to change style on an element?
Ans. Between CSS and javascript is a weird symmetry. CSS style rules are layed on top of the DOM. The CSS property names like “font-weight” are transliterated into “myElement.style.fontWeight”. The class of an element can be swapped out. For example:
document.getElementById( "myText" ).style.color = "green" ; document.getElementById( "myText" ).style.fontSize = "20" ; //or document.getElementById( "myText" ).className = "regular" ; |
61. How to remove the event listener: ?
Ans.
document.getElementById( "hitme4" ).removeEventListener( "click" , hitme4, false ); |
62. How to make elements invisible ?
Ans. Change the “visibility” attribute of the style object associated with your element. Remember that a hidden element still takes up space, use “display” to make the space disappear as well.
if ( x == y) { myElement.style.visibility = 'visible' ; } else { myElement.style.visibility = 'hidden' ; } |
63. How to set the cursor to wait ?
Ans. In theory, we should cache the current state of the cursor and then put it back to its original state.
document.body.style.cursor = 'wait' ; //do something interesting and time consuming document.body.style.cursor = 'auto' ; |
64. How to reload the current page ?
Ans.
window.location.reload( true ); |
65. how to force a page to go to another page using JavaScript ?
Ans.
location.href= http://www.google.com ; |
66. How to create a function using function constructor?
Ans. The following example creates a function called square with argument x and returns x multiplied by itself.
var square = new Function ( "x" , "return x*x" ); |
67. Have you heard of Douglas Crockford?
Ans. Yes he is the “inventor” of JSON.
68. What debugging tools do you use?
Ans. Firebug in Firefox (console.log(); method) and Visual Studio in IE (‘debug’ command inserted in javascript file).
No comments:
Post a Comment