JavaScript Questions & Answers – Error Handling – I

«
»

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Error Handling – I”.

1. What is the code snippet to go back to a history twice?
a) history(2);
b) history(-2);
c) history.go(-2);
d) history.go(2);
View Answer

Answer: c
Explanation: The go() method loads a specific URL from the history list. The above code snippet goes back 2, like clicking the Back button twice.
advertisement

2. If the window has child windows, how will the browsing histories be affected?
a) Numerically interleaved
b) Chronologically interleaved
c) Both Numerically and Chronologically interleaved
d) Numerically or Chronologically interleaved
View Answer

Answer: b
Explanation: If a window contains child windows, the browsing histories of the child windows are chronologically interleaved with the history of the main window. The opener property returns a reference to the window that created the window.

3. The length property belongs to which of the following objects?
a) Window
b) Element
c) History
d) Document
View Answer

Answer: c
Explanation: The length property of the History object specifies the number of elements in the browsing history list. The property returns at least 1, because the list includes the currently loaded page.

4. What is the datatype of the go() method’s parameter?
a) String
b) Integer
c) Double
d) Float
View Answer

Answer: b
Explanation: The go() method takes an integer argument and can skip any number of pages forward and backward in the history list.

5. What is the special feature of modern web applications?
a) Can alter contents without loading document
b) Must load the document to manipulate
c) Remains static
d) Can’t be altered at all
View Answer

Answer: a
Explanation: Modern web applications can dynamically alter their own content without loading a new document.

6. The navigator property belongs to which of the following object?
a) Document
b) Window
c) Navigator
d) Location
View Answer

Answer: c
Explanation: The navigator property of a Window object refers to a Navigator object that contains browser vendor and version number information. Navigator object property includes appCodeName, appVersion, appName etc.

7. What is the vendor-neutral synonym for navigator?
a) staticData
b) purposeInformation
c) dataInformation
d) clientInformation
View Answer

Answer: d
Explanation: IE supports clientInformation as a vendor-neutral synonym for a navigator. The navigator property of a Window object refers to a Navigator object that contains browser vendor and version number information.
advertisement

8. Which is the preferred testing nowadays for scripting?
a) Software testing
b) Feature testing
c) Blackbox testing
d) Whitebox testing
View Answer

Answer: b
Explanation: The “browser-sniffing” approach is problematic because it requires constant tweaking as new browsers and new versions of existing browsers are introduced. Today, feature testing is preferred rather than making assumptions about particular browser versions and their features, you simply test for the feature (i.e., the method or property) you need.

9. Which of the below properties can be used for browser sniffing?
a) platform
b) appVersion
c) both platform and appVersion
d) appName
View Answer

Answer: c
Explanation: The platform and appVersion can be found out in the navigator object properties.

10. Where is the information of the userAgent property located?
a) appId
b) appName
c) platform
d) appVersion
View Answer

Answer: d
Explanation: The string that the browser sends in its USER-AGENT HTTP header. This property typically contains all the information in appVersion and may contain additional details as well.

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

function myFunction() 
{
    document.getElementById("demo").innerHTML = Boolean(10 > 9);
}

a) true
b) false
c) error
d) 0
View Answer

Answer: a
Explanation: The boolean function returns the boolean values. Since 10 is greater than 9 the boolean function returns true.

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

advertisement
var b5 = Boolean('false');
document.getElementById("demo").innerHTML =b5;

a) False
b) True
c) Error
d) Undefined
View Answer

Answer: b
Explanation: The boolean function returns the boolean values. The boolean function returns true for any non empty string even if the string is false.

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

function myFunction() 
{
  var x = "";
  document.getElementById("demo").innerHTML = Boolean(x);
}

a) true
b) false
c) 0
d) 1
View Answer

Answer: b
Explanation: When an empty string is passed to the boolean function then the function returns false. The boolean function returns true or false according to the input passed to it.

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

function myFunction() 
{
   var x = 10 / "H";
   document.getElementById("demo").innerHTML = Boolean(x);
}

a) True
b) False
c) Error
d) Undefined
View Answer

Answer: b
Explanation: The value return by the boolean method depends on the input passed to it. The NaN value when passed to the boolean function returns false.
advertisement

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

function myFunction() 
{
   var x = null;
   document.getElementById("demo").innerHTML = Boolean(x);
}

a) True
b) False
c) Error
d) Undefined
View Answer

Answer: b
Explanation: The value return by the boolean method depends on the input passed to it. The NULL value when passed to the boolean function returns false.

Sanfoundry Global Education & Learning Series – Javascript Programming.

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