250+ TOP MCQs on Server-Side JavaScript and Answers

Javascript Multiple Choice Questions on “Server-Side JavaScript”.

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

Answer: b
Clarification: 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)

Answer: c
Clarification: 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)

Answer: d
Clarification: 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()

Answer: a
Clarification: 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

Answer: b
Clarification: 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

  250+ TOP MCQs on Scripting CSS and Answers

Answer: a
Clarification: 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

Answer: c
Clarification: 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();

Answer: a
Clarification: 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);

Answer: b
Clarification: ”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

Answer: d
Clarification: 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.

  250+ TOP MCQs on The Closure Compiler and Answers

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

Answer: b
Clarification: 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("
navigator.appCodeName: "+navigator.appCodeName);

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

Answer: a
Clarification: 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("
navigator.language: "+navigator.language);

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

Answer: c
Clarification: 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("
navigator.appVersion: "+navigator.appVersion);

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

Answer: a
Clarification: 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("
screen.width: "+screen.width);

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

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top