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
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
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
Explanation: The removeAllListeners(name) is used to remove all handlers from name events represented as :
emitter.removeAllListeners(name)
4. Which function is a synonym for on()?
a) addListener()
b) listeners()
c) once()
d) add()
View Answer
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
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().
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
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
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));
8. What is the method used to pause “data” events?
a) s.pause();
b) s.stop();
c) s.halt();
d) s.wait();
View Answer
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
Explanation: ”EOF” stands for end of file.The above code snippet gets “end” event fired on EOF when no more data will arrive.
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
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
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
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
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
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
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.
- Practice Programming MCQs
- Practice Information Science MCQs
- Check Programming Books
- Apply for Computer Science Internship
- Check JavaScript Books