Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger


Sunday 14 September 2008

Javascript Interview Questions and Answers 6

How to Accessing Elements using javascript?
To do something interesting with HTML elements, we must first be able to uniquely identify which element we want. In the example






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.






onclick="showStatus()" />


What looping structures are there in JavaScript?
for, while, do-while loops, but no foreach.

To put a "close window" link on a page ?
Close

How to hide javascript code from old browsers that dont run it?
Use the below specified style of comments or Use the tags and code the display html statements between these and this will appear on the page if the browser does not support javascript

How to comment javascript code?
Use // for line comments and
/*

*/ for block comments

Name the numeric constants representing max,min values
Number.MAX_VALUE
Number.MIN_VALUE

What does javascript null mean?
The null value is a unique value representing no value or no object.
It implies no object,or null string,no valid boolean value,no number and no array object.

How do you create a new object in JavaScript?
var obj = new Object(); or var obj = {};

How do you assign object properties?
obj["age"] = 17 or obj.age = 17.

What’s a way to append a value to an array?
arr[arr.length] = value;

What is this keyword?
It refers to the current object.

No comments:

Post a Comment