JavaScript Questions & Answers – Node Operations in JavaScript – II

This set of JavaScript Interview Questions and Answers for freshers focuses on “Node Operations in JavaScript – II”.

1. What does a Node object represent?
a) Single node
b) Set of nodes
c) Sequence of nodes
d) Node array
View Answer

Answer: a
Explanation: The Node object represents a single node in the document tree. A node can be an element node, an attribute node, a text node, or any other of the node types explained in the Node Types chapter.

2. What does the nodeName of the nodeType Document return?
a) doctype name
b) target
c) #comment
d) #document
View Answer

Answer: d
Explanation: The nodeName of the nodeType Document returns #document. If the node is an element node, the nodeName property will return the tag name. If the node is an attribute node, the nodeName property will return the name of the attribute.

3. What is the purpose of the method item()?
a) Returns node after the specified index
b) Returns node before the specified index
c) Returns node at specified index
d) Returns the node following the specified node
View Answer

Answer: c
Explanation: The method item() returns the node at the specified index in a node list. The nodes are sorted as they appear in the source code, and the index starts at 0.A Node object’s collection of child nodes is an example of a NodeList object.
advertisement
advertisement

4. How can the nodes in the node list be accessed?
a) Key
b) Index number
c) Looping
d) Value
View Answer

Answer: b
Explanation: The nodes in the node list can be accessed through their index number. The nodes are sorted as they appear in the source code, and the index starts at 0.

5. Which of the following is the child(s) of the node type EntityReference?
a) Element
b) Text
c) Both Element and Text
d) Entity
View Answer

Answer: c
Explanation: The createEntityReference() method creates the specified EntityReference Object. The children of the node type EntityReference are Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Which node type represents the root-node of the DOM tree?
a) Document
b) DocumentFragment
c) DocumentType
d) Entity
View Answer

Answer: a
Explanation: Everything inside an html document is classified in the form of different nodes. The node type Document represents the root-node of the DOM tree, the entire document.

7. What is the purpose of the DocumentFragment node type?
a) To hold a portion of a document
b) To split the document into fragments
c) To hold the entire document
d) To hold the fragments
View Answer

Answer: a
Explanation: The DocumentFragment node type represents a “lightweight” Document object that has no parent. It is used as a lightweight version of Document that stores a segment of a document structure comprised of nodes just like a standard document.
advertisement

8. How many nodetype – named constants are available?
a) 13
b) 11
c) 12
d) 10
View Answer

Answer: c
Explanation: DOM nodes can be of various types, such as element nodes and text nodes, and each node has a nodeType property giving its type. There are totally 12 nodetype – named constants available.

9. Which of the following Node types have a node value equal to null?
a) Document
b) DocumentFragment
c) DocumentType
d) All of the mentioned
View Answer

Answer: d
Explanation: All the three node types namely, Document, DocumentFragment, DocumentType have a node value equal to null. If the node is an element node, the nodeType property will return 1. If the node is an attribute node, the nodeType property will return 2.
advertisement

10. How many node object properties are there?
a) 12
b) 14
c) 16
d) 17
View Answer

Answer: c
Explanation: Node interface is the primary datatype for the entire Document Object Model. The node is used to represent a single XML element in the entire document tree. There are totally 16 node object properties.

Sanfoundry Global Education & Learning Series – Javascript Programming.

To practice all areas of JavaScript for Interviews, here is complete set of 1000+ Multiple Choice Questions and Answers on Javascript.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.