JavaScript Questions and Answers Part-19

1. 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) false
c) no
d) undefined

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.

2. 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
Explanation: The JavaScript navigator object is used for browser detection. appCodeName returns the browser name.

3. 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
Explanation: navigator.language returns the language of the browser. It is supported in Netscape and Firefox only.

4. 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
Explanation: navigator.version is present in the navigator object. appVersion returns the version of the browser.

5. 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
Explanation: screen.width method is provided in the screen object of Javascript. It returns the width of the browser screen

6. Rhino is originated by _______
a) Microsoft
b) Mozilla
c) Apple
d) Chrome

Answer: b
Explanation: Rhino is a JavaScript engine written fully in Java and managed by the Mozilla Foundation as open source software. Rhino is free software from Mozilla.

7. Which of the following are global functions that are not part of core JavaScript?
a) spawn(f);
b) trim();
c) exult();
d) eval()

Answer: a
Explanation: The spawn(f) runs f() or loads and executes file f in a new thread.

8. Which of the following reads the textual contents of a URL and returns as a string?
a) spawn(f);
b) load(filename,…);
c) readFile(file);
d) readUrl(url);

Answer: d
Explanation: Rhino defines a handful of important global functions that are not part of core JavaScript in which readUrl(url) reads the textual contents of a URL and return as a string.

9. Which Rhino command quits Rhino environment?
a) terminate()
b) exit()
c) quit()
d) close()

Answer: c
Explanation: quit() is a predefined command in rhino. The quit() command makes Rhino exit.

10. Which is a useful way to try out small and simple Rhino programs and one-liners?
a) Starting an interactive shell
b) Starting a one to one shell
c) Creating a thread to do simple programs
d) Starting a multiple shell

Answer: a
Explanation: Starting an interactive shell