JavaScript Questions & Answers – JavaScript Benchmarking and Logging with perfLogger – I

«
»

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “JavaScript Benchmarking and Logging with perfLogger – I”.

1. How many default number methods are available in JavaScript?
a) 5
b) 6
c) 7
d) 8
View Answer

Answer: c
Explanation: There are a total of 7 default number methods in JavaScript namely:

  1. constructor()
  2. toExponential()
  3. toFixed()
  4. toLocaleString()
  5. toPrecision()
  6. toString()
  7. valueOf()
advertisement

2. What is the observer effect?
a) Observing influences outcome
b) Observing never influences outcome
c) Observing and the outcome are independent
d) Observing and the outcome are not related
View Answer

Answer: a
Explanation: The observer effect says that simply observing an act influences its outcome. This is often the result of instruments that, by necessity, alter the state of what they measure in some manner.

3. Which of the following are ways to benchmark code?
a) Timing the code
b) Calculating the number of operations performed
c) Timing the code & Calculating the number of operations performed
d) Calculating the number of lines
View Answer

Answer: c
Explanation: There are a couple of ways to benchmark code—either by timing it or by calculating the number of operations performed during execution. Both of them help in calculating how efficient and modular the code.

4. How to calculate the run time of a code?
a) Start time – End time
b) End time – Start time
c) Start time/ End time
d) Start time * End time
View Answer

Answer: b
Explanation: Run-time statements use the static resources created by compile-time statements, but can also create, use, and destroy dynamic resources at run time. The run time of code can be calculated as:
run time = end time – start time

5. According to the workflow of a runtime logging, what happens after calculating the run time?
a) Display to screen
b) Log to server
c) Either Display to screen or Log to server
d) Server to log
View Answer

Answer: c
Explanation: According to the workflow of a runtime logging, after calculating the run time, decision boxes are kept that will check to either display to the debug screen or log to the server.
advertisement

6. Which of the following object is used to post the data to an external process, say savePerfData?
a) XML
b) XBT
c) XHR
d) XTR
View Answer

Answer: c
Explanation: XHR(XMLHttpRequest) is an API in the form of an object whose methods transfer data between a web browser and a web server. The benchmarking process will call the external process. We use XHR object to post the data to the external process.

7. Where does the external process save the result of the test?
a) Normal file
b) Flat file
c) Folder
d) .exe file
View Answer

Answer: b
Explanation: A flat file consists of a single table of data. It allows the user to specify data attributes, such as columns and data types table by table, and stores those attributes separate from applications. The external process, say savePerfData should in turn save the results of the test in a flat file.

8. Which function is used to start the time logging?
a) startTimeLogging()
b) start()
c) Loggingstart()
d) startLogging()
View Answer

Answer: a
Explanation: The function startTimeLogging() is used to start the time logging. The startTimeLogging() method captures the timing data for ad hoc, etc for referencing an uncached document.location.

9. Which of the following attribute of form tag is not set by using document object in JavaScript?
a) Target
b) Enctype
c) Action
d) Logging
View Answer

Answer: d
Explanation: Target, enctype & action can be set by using the document object in JavaScript. The Document object has various properties that refer to other objects which allow access to and modification of document content.
advertisement

10. What will be the output of the following JavaScript function?

<script type="text/javascript">
var name1 = "Sanfoundry";
function DisplayName () {
var name2 = " The Best"; 
document.write(name1+name2); 
}
</script>

a) SanfoundryThe Best
b) Sanfoundry The Best
c) Object required error
d) Javascript Error
View Answer

Answer: b
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. The output for the above code is Sanfoundry The Best.

Sanfoundry Global Education & Learning Series – Javascript Programming.

advertisement

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn