JavaScript Questions & Answers – Server-Side JavaScript

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Server-Side JavaScript”.

1. What are the events generated by the Node objects called?
a) generators
b) emitters
c) dispatchers
d) highevents
View Answer

Answer: b
Explanation: There are two classes of events one is called event listener and the other is called event emitter. Node objects that generate events (known as event emitters) define an on() method for registering handlers.

2. What is the function used to deregister event handler ‘f’?
a) deleteAllListeners(name)
b) deleteListener(name,f)
c) removeListener(name,f)
d) removeAllListeners(name)
View Answer

Answer: c
Explanation: The removeEventListener() method removes an event handler that has been attached with the addEventListener() method. The removeListeners(name,f) is used to deregister event handler f represented as :
emitter.removeListener(name,f)

3. What is the function used to remove all handlers for name events?
a) deleteAllListeners(name)
b) deleteListener(name,f)
c) removeListener(name,f)
d) removeAllListeners(name)
View Answer

Answer: d
Explanation: The removeAllListeners(name) is used to remove all handlers from name events represented as :
emitter.removeAllListeners(name)
advertisement
advertisement

4. Which function is a synonym for on()?
a) addListener()
b) listeners()
c) once()
d) add()
View Answer

Answer: a
Explanation: The on() method is used for registering handlers. addListener() is a synonym for on().

5. Which of the following is an event emitter?
a) once
b) process
c) listeners
d) on
View Answer

Answer: b
Explanation: The process object is an event emitter. The Node defines other important globals under the process namespaces that contain properties of that object like version, argv, env, pid, getuid(), cwd(), chdir() and exit().
Note: Join free Sanfoundry classes at Telegram or Youtube

6. When do uncaught exceptions generate events?
a) When handlers are registered
b) When handlers are deregistered
c) When handler functions are called
d) When handlers do not have a matching catch clause
View Answer

Answer: a
Explanation: The on() method and addListener() method perform the same task of acting as an event emitter. The on() and addListener() method is used for registering handlers.

7. Which among the following POSIX signals generate events?
a) SIGDOWN
b) SIGFLOAT
c) SIGINT
d) SIGSHORT
View Answer

Answer: c
Explanation: The SIGINT is a POSIX signal that generates event. Simple code like below can do a proper clean up and exit on CTRL-C or SIGINT passed from command line / other application to the nodejs app’s ProcessID.

  process.on('SIGINT', function()
       console.log('SIGINT');
       cleanup()
       process.exit(1));
advertisement

8. What is the method used to pause “data” events?
a) s.pause();
b) s.stop();
c) s.halt();
d) s.wait();
View Answer

Answer: a
Explanation: Data events are the events which are performed by either the user or the browser. The above code snippet is used to pause data events, for throttling uploads.

9. When the “end” event fires on EOF when no more data will arrive, which function is called?
a) s.on(“data”,f);
b) s.on(“end”,f);
c) s.on(“error”,f);
d) s.on(“default”,f);
View Answer

Answer: b
Explanation: ”EOF” stands for end of file.The above code snippet gets “end” event fired on EOF when no more data will arrive.
advertisement

10. What will be the return value of the write() method when the Node cannot write the data immediately and has to buffer it internally?
a) 0
b) 1
c) True
d) False
View Answer

Answer: d
Explanation: The write() method writes HTML expressions or JavaScript code to a document. The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML. write() method never blocks. If Node cannot write the data immediately and has to buffer it internally, the write() method returns false.

11. If the user presses “ok” in the dialog box then what will be the output of the following JavaScript code?

function msg()
{  
    var v= confirm("Are u sure?");  
    if(v==true)
    {  
        alert("yes");  
    }  
    else
    {  
        alert("no");  
    }  
}

a) true
b) yes
c) no
d) undefined
View Answer

Answer: b
Explanation: The function confirm is present in the window object. confirm() method displays the confirm dialog box containing a message with ok and cancel button.

12. What will be the output of the following JavaScript code?

document.writeln("<br/>navigator.appCodeName: "+navigator.appCodeName);

a) Browser name
b) Version
c) Error
d) Undefined
View Answer

Answer: a
Explanation: The JavaScript navigator object is used for browser detection. appCodeName returns the browser name.

13. What will be the output of the following JavaScript code?

document.writeln("<br/>navigator.language: "+navigator.language);

a) Broswer name
b) Browser language
c) Browser version
d) Error
View Answer

Answer: c
Explanation: navigator.language returns the language of the browser. It is supported in Netscape and Firefox only.

14. What will be the output of the following JavaScript code?

document.writeln("<br/>navigator.appVersion: "+navigator.appVersion);

a) Browser version
b) Browser name
c) Browser language
d) Error
View Answer

Answer: a
Explanation: navigator.version is present in the navigator object. appVersion returns the version of the browser.

15. What will be the output of the following JavaScript code?

document.writeln("<br/>screen.width: "+screen.width);

a) Browser length
b) Browser width
c) Browser area
d) Error
View Answer

Answer: b
Explanation: screen.width method is provided in the screen object of Javascript. It returns the width of the browser screen

Sanfoundry Global Education & Learning Series – Javascript Programming.

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.