Node JS Quiz Questions and Answers

Which method is used to compare the placement of two nodes in the DOM hierarchy (document)?

Answer :
  • compareDocumentPosition()

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.

What is the purpose of the method getUserData(key)?

Answer :
  • Returns the associated object

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.

Which of the following Node object property returns the node immediately before a node?

Answer :
  • previousSibling

Explanation :

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

What is the purpose of the Node object property owner document?

Answer :
  • Returns the root element

Explanation :

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

Which of the following is the correct way to get a joint path?

Answer :
  • path.join('/test', 'test1', '2slashes/1slash', 'tab', '..')

Explanation :

path.join([path1][, path2][, ...]) joins all arguments together and normalize the resulting path.

An approach to connect the output of one stream to the input of another stream is known as...

Answer :
  • chaining process

Explanation :

chaining process is an approach to connect the output of one stream to the input of another

Which of the following codes print the Endianness of the operating system?

Answer :
  • console.log('endianness : ' + os.endianness());

Explanation :

os.endianness() returns the endianness of the CPU. Possible values are "BE" or "LE".

Which of the following class is used to create and consume custom events in Node.js?

Answer :
  • eventEmitter

Explanation :

EventEmitter is used to create and consume custom events in Node.js

Which module is used to serve static resources in Node.js?

Answer :
  • Node-static

Explanation :

Node-static is used to serve static resources in Node.js

Node.js terminal (REPL) is used for _________.

Answer :
  • Testing Node.js/JavaScript expressions

Explanation :

Repl is used for Testing node.js/JavaScript expressions.