- Home
- Interview Questions
- Javascript
You can create an array of arrays, which amounts to the same thing:
var myArray = [[1,2], [3,4], [5,6]];
alert(myArray[1][0]); // alerts '3'
It’s true that there is usually more than one type of loop that will solve any particular programming problem. You can use the one you feel most comfortable with, though it’s usually good practice to use whichever loop makes the most sense (in conjunction with your chosen variable names) in the context of what your code sets out to do.
Yes, you can use the continue command. It works pretty much like break, but instead of canceling the loop and continuing code execution from after the closing brace, continue only cancels the current trip around the loop and moves on to the next one.
An object’s constructor function is quite a portable entity. If you link into your page a JavaScript file containing an object constructor function, you have the means to create objects and use their properties and methods throughout your code.
Yes, you can use the hasChildNodes() method. This method returns a Boolean value of true if the node has one or more child nodes, or false if not. Remember that attribute nodes and text nodes cannot have child nodes, so the method will always return false if applied to these types of node.
Not at all. Just about every browser has some DOM inspection tools built into the developer tools. However, Mozilla’s DOM Inspector gives a particularly clear view of the DOM hierarchy and the parameters of individual nodes; that’s why I presented it here.
Each has its advantages and disadvantages. To insert a chunk of HTML into a
document, using innerHTML is quick and easy. However, it returns no
references to the code you’ve inserted, so you can’t carry out operations on that
content very easily. DOM methods offer finer-grained control for manipulating
page elements.
Wherever you use innerHTML, the same result is achievable using DOM
methods, though usually with a little more code.
Remember, too, that innerHTML is not a W3C standard. It is well supported
currently, but there’s no guarantee that that will always be so.
The DOM Core describes a basic nucleus of DOM methods that are applicable not just to HTML pages, but also pages written in any similar markup language— XML, for example. HTML DOM is a larger collection of additional methods relating specifically to HTML pages. They do offer some shorthand ways of carrying out certain tasks, at the expense of making your code a little less portable to non-HTML applications.
Remember that the browser might have been set up by the service provider or
employer with JavaScript turned off by default, in an effort to improve security.
This is particularly likely in an environment such as a school or an Internet cafe.
Additionally, some corporate firewalls, ad-blocking, and personal antivirus
software prevent JavaScript from running, and some mobile devices have web
browsers without complete JavaScript support.