JavaScript Questions & Answers – Node Operations in JavaScript – I

«
»

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Node Operations in JavaScript – I”.

1. How many node types are there in total?
a) 11
b) 12
c) 13
d) 14
View Answer

Answer: b
Explanation: There are total of 12 node types. The nodeType property returns the node type, as a number, of the specified node.
advertisement

2. What is the purpose of the Node object property ownerDocument?
a) Returns the root element
b) Returns the last element
c) Returns the parent node
d) Returns the immediate node
View Answer

Answer: a
Explanation: The ownerDocument property returns the owner document of a node, as a Document object. It returns the root element for a node.

3. Which of the following Node object property returns the local part of the name of a node?
a) lastName
b) localName
c) firstName
d) objectname
View Answer

Answer: b
Explanation: The Node object property localName Returns the local part of the name of a node. If the selected node is not an element or attribute, this property returns NULL.

4. What is the property textContent?
a) Sets the textual content of a node
b) Returns the textual content of a node
c) Sets & Returns the textual content of a node
d) Modifies texual content
View Answer

Answer: c
Explanation: The property textContent sets or returns the textual content of a node and its descendants. If you set the textContent property, any child nodes are removed and replaced by a single Text node containing the specified string.
advertisement

5. How many Node object methods are available?
a) 18
b) 19
c) 20
d) 21
View Answer

Answer: a
Explanation: The Node object represents a single node in the document tree. There are totally 18 node object methods.

6. Which of the following Node object property returns the node immediately before a node?
a) previousSibling
b) textContent
c) index
d) localName
View Answer

Answer: a
Explanation: The node object property previousSibling returns the node immediately before a node. The returned node is returned as a Node object.

7. What is the purpose of the method getUserData(key)?
a) Returns the associated object
b) Gets the user data
c) Returns the user data
d) Gets the user key
View Answer

Answer: a
Explanation: The method getUserData(key) returns the object associated to a key on a this node. The object must first have been set to this node by calling setUserData with the same key.
advertisement

8. How to test if two nodes are equal?
a) isEqualNode()
b) equal()
c) ==
d) equalto()
View Answer

Answer: a
Explanation: The method isEqualNode() is used to test if two nodes are equal. Two nodes are equal when they have the same type, defining characteristics (for elements, this would be their ID, number of children, and so forth), its attributes match, and so on.

9. How to associate an object to a key on a node?
a) getUserData()
b) cloneNode()
c) setUserData(key,data,handler)
d) clonedata()
View Answer

Answer: c
Explanation: The Node.setUserData() method allows a user to attach (or remove) data to an element, without needing to modify the DOM. This method is used to associate an object to a key on a node.

10. Which method is used to compare the placement of two nodes in the DOM hierarchy (document)?
a) compareDocumentPosition()
b) cloneNode()
c) getUserData()
d) getFeature()
View Answer

Answer: a
Explanation: The compareDocumentPosition() method is used to compare the placement of two nodes in the DOM hierarchy (document). The return value is an integer value whose bits represent the calling Node’s relationship to otherNode within the Document.
advertisement

Sanfoundry Global Education & Learning Series – Javascript Programming.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn